28.2.5. Pod の作成
Pod 定義ファイルまたはテンプレートファイルを使用して Pod を定義できます。以下は、1 つのコンテナーを作成して NFS ボリュームを読み書きアクセス用にマウントする Pod 仕様です。
例28.3 Pod オブジェクトの定義
apiVersion: v1 kind: Pod metadata: name: hello-openshift-nfs-pod 1 labels: name: hello-openshift-nfs-pod spec: containers: - name: hello-openshift-nfs-pod image: openshift/hello-openshift 2 ports: - name: web containerPort: 80 volumeMounts: - name: nfsvol 3 mountPath: /usr/share/nginx/html 4 securityContext: supplementalGroups: [100003] 5 privileged: false volumes: - name: nfsvol persistentVolumeClaim: claimName: nfs-pvc 6
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 1 Image(s): fedora/S3 Node: ose70.rh7/192.168.234.148 2 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 3 ReadOnly: false default-token-a06zb: Type: Secret (a secret that should populate this volume) SecretName: default-token-a06zb Events: 4 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
oc get pod <name> -o yaml
コマンドでは、Pod の承認に使用される SCC や Pod のユーザー ID とグループ ID、SELinux ラベルなどの内部情報がさらに表示されます。
[root@ose70 nfs]# oc get pod hello-openshift-nfs-pod -o yaml apiVersion: v1 kind: Pod metadata: annotations: openshift.io/scc: restricted 1 creationTimestamp: 2016-03-21T13:59:47Z labels: name: hello-openshift-nfs-pod name: hello-openshift-nfs-pod namespace: default 2 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 3 serviceAccount: default serviceAccountName: default terminationGracePeriodSeconds: 30 volumes: - name: nfsvol persistentVolumeClaim: claimName: nfs-pvc 4 - 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