28.2.5. 创建 Pod
pod 定义文件或模板文件可用于定义 pod。以下是创建单个容器并挂载 NFS 卷的 pod 规格,以便进行读写访问:
例 28.3. Pod 对象定义
apiVersion: v1
kind: Pod
metadata:
name: hello-openshift-nfs-pod
labels:
name: hello-openshift-nfs-pod
spec:
containers:
- name: hello-openshift-nfs-pod
image: openshift/hello-openshift
ports:
- name: web
containerPort: 80
volumeMounts:
- name: nfsvol
mountPath: /usr/share/nginx/html
securityContext:
supplementalGroups: [100003]
privileged: false
volumes:
- name: nfsvol
persistentVolumeClaim:
claimName: nfs-pvc
将 pod 定义保存到文件中,如 nfs.yaml,然后创建 pod:
# oc create -f nfs.yaml
pod "hello-openshift-nfs-pod" created
验证 pod 是否已创建:
# oc get pods
NAME READY STATUS RESTARTS AGE
hello-openshift-nfs-pod 1/1 Running 0 4s
oc describe pod 命令中显示更多详细信息:
[root@ose70 nfs]# oc describe pod hello-openshift-nfs-pod
Name: hello-openshift-nfs-pod
Namespace: default
Image(s): fedora/S3
Node: ose70.rh7/192.168.234.148
Start Time: Mon, 21 Mar 2016 09:59:47 -0400
Labels: name=hello-openshift-nfs-pod
Status: Running
Reason:
Message:
IP: 10.1.0.4
Replication Controllers: <none>
Containers:
hello-openshift-nfs-pod:
Container ID: docker://a3292104d6c28d9cf49f440b2967a0fc5583540fc3b062db598557b93893bc6f
Image: fedora/S3
Image ID: docker://403d268c640894cbd76d84a1de3995d2549a93af51c8e16e89842e4c3ed6a00a
QoS Tier:
cpu: BestEffort
memory: BestEffort
State: Running
Started: Mon, 21 Mar 2016 09:59:49 -0400
Ready: True
Restart Count: 0
Environment Variables:
Conditions:
Type Status
Ready True
Volumes:
nfsvol:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: nfs-pvc
ReadOnly: false
default-token-a06zb:
Type: Secret (a secret that should populate this volume)
SecretName: default-token-a06zb
Events:
FirstSeen LastSeen Count From SubobjectPath Reason Message
───────── ──────── ───── ──── ───────────── ────── ───────
4m 4m 1 {scheduler } Scheduled Successfully assigned hello-openshift-nfs-pod to ose70.rh7
4m 4m 1 {kubelet ose70.rh7} implicitly required container POD Pulled Container image "openshift3/ose-pod:v3.1.0.4" already present on machine
4m 4m 1 {kubelet ose70.rh7} implicitly required container POD Created Created with docker id 866a37108041
4m 4m 1 {kubelet ose70.rh7} implicitly required container POD Started Started with docker id 866a37108041
4m 4m 1 {kubelet ose70.rh7} spec.containers{hello-openshift-nfs-pod} Pulled Container image "fedora/S3" already present on machine
4m 4m 1 {kubelet ose70.rh7} spec.containers{hello-openshift-nfs-pod} Created Created with docker id a3292104d6c2
4m 4m 1 {kubelet ose70.rh7} spec.containers{hello-openshift-nfs-pod} Started Started with docker id a3292104d6c2
还有更多内部信息,包括用于授权 pod、pod 的用户和组 ID、SELinux 标签等,如 oc get pod <name> -o yaml 命令所示:
[root@ose70 nfs]# oc get pod hello-openshift-nfs-pod -o yaml
apiVersion: v1
kind: Pod
metadata:
annotations:
openshift.io/scc: restricted
creationTimestamp: 2016-03-21T13:59:47Z
labels:
name: hello-openshift-nfs-pod
name: hello-openshift-nfs-pod
namespace: default
resourceVersion: "2814411"
selflink: /api/v1/namespaces/default/pods/hello-openshift-nfs-pod
uid: 2c22d2ea-ef6d-11e5-adc7-000c2900f1e3
spec:
containers:
- image: fedora/S3
imagePullPolicy: IfNotPresent
name: hello-openshift-nfs-pod
ports:
- containerPort: 80
name: web
protocol: TCP
resources: {}
securityContext:
privileged: false
terminationMessagePath: /dev/termination-log
volumeMounts:
- mountPath: /usr/share/S3/html
name: nfsvol
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-a06zb
readOnly: true
dnsPolicy: ClusterFirst
host: ose70.rh7
imagePullSecrets:
- name: default-dockercfg-xvdew
nodeName: ose70.rh7
restartPolicy: Always
securityContext:
supplementalGroups:
- 100003
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
volumes:
- name: nfsvol
persistentVolumeClaim:
claimName: nfs-pvc
- name: default-token-a06zb
secret:
secretName: default-token-a06zb
status:
conditions:
- lastProbeTime: null
lastTransitionTime: 2016-03-21T13:59:49Z
status: "True"
type: Ready
containerStatuses:
- containerID: docker://a3292104d6c28d9cf49f440b2967a0fc5583540fc3b062db598557b93893bc6f
image: fedora/S3
imageID: docker://403d268c640894cbd76d84a1de3995d2549a93af51c8e16e89842e4c3ed6a00a
lastState: {}
name: hello-openshift-nfs-pod
ready: true
restartCount: 0
state:
running:
startedAt: 2016-03-21T13:59:49Z
hostIP: 192.168.234.148
phase: Running
podIP: 10.1.0.4
startTime: 2016-03-21T13:59:47Z