28.2.6. 创建额外 Pod 以引用 Same PVC
此 pod 定义在同一命名空间中创建,使用不同的容器。但是,您可以通过在下面的 volumes 部分中指定声明名称来使用相同的后备存储:
例 28.4. Pod 对象定义
apiVersion: v1 kind: Pod metadata: name: busybox-nfs-pod 1 labels: name: busybox-nfs-pod spec: containers: - name: busybox-nfs-pod image: busybox 2 command: ["sleep", "60000"] volumeMounts: - name: nfsvol-2 3 mountPath: /usr/share/busybox 4 readOnly: false securityContext: supplementalGroups: [100003] 5 privileged: false volumes: - name: nfsvol-2 persistentVolumeClaim: claimName: nfs-pvc 6
将 pod 定义保存到文件中,如 nfs-2.yaml,并创建 pod:
# oc create -f nfs-2.yaml pod "busybox-nfs-pod" created
验证 pod 是否已创建:
# oc get pods NAME READY STATUS RESTARTS AGE busybox-nfs-pod 1/1 Running 0 3s
oc describe pod
命令中显示更多详细信息:
[root@ose70 nfs]# oc describe pod busybox-nfs-pod Name: busybox-nfs-pod Namespace: default Image(s): busybox Node: ose70.rh7/192.168.234.148 Start Time: Mon, 21 Mar 2016 10:19:46 -0400 Labels: name=busybox-nfs-pod Status: Running Reason: Message: IP: 10.1.0.5 Replication Controllers: <none> Containers: busybox-nfs-pod: Container ID: docker://346d432e5a4824ebf5a47fceb4247e0568ecc64eadcc160e9bab481aecfb0594 Image: busybox Image ID: docker://17583c7dd0dae6244203b8029733bdb7d17fccbb2b5d93e2b24cf48b8bfd06e2 QoS Tier: cpu: BestEffort memory: BestEffort State: Running Started: Mon, 21 Mar 2016 10:19:48 -0400 Ready: True Restart Count: 0 Environment Variables: Conditions: Type Status Ready True Volumes: nfsvol-2: Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace) ClaimName: nfs-pvc ReadOnly: false default-token-32d2z: Type: Secret (a secret that should populate this volume) SecretName: default-token-32d2z Events: FirstSeen LastSeen Count From SubobjectPath Reason Message ───────── ──────── ───── ──── ───────────── ────── ─────── 4m 4m 1 {scheduler } Scheduled Successfully assigned busybox-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 249b7d7519b1 4m 4m 1 {kubelet ose70.rh7} implicitly required container POD Started Started with docker id 249b7d7519b1 4m 4m 1 {kubelet ose70.rh7} spec.containers{busybox-nfs-pod} Pulled Container image "busybox" already present on machine 4m 4m 1 {kubelet ose70.rh7} spec.containers{busybox-nfs-pod} Created Created with docker id 346d432e5a48 4m 4m 1 {kubelet ose70.rh7} spec.containers{busybox-nfs-pod} Started Started with docker id 346d432e5a48
如您所见,两个容器都使用附加到后端上同一 NFS 挂载的相同存储声明。