Useful Resources: Persistent Volumes Claim , Pod to Use a PV
题干
For this question, please set this context (In exam, diff cluster name)
kubectl config use-context kubernetes-admin@kubernetes
A Kubernetes pod definition file named nginx-pod-cka.yaml
is available. Your task is to make the following modifications to the manifest file:
- Create a Persistent Volume Claim (PVC) with the name
nginx-pvc-cka
. This PVC should request80Mi
of storage from an existing Persistent Volume (PV) named nginx-pv-cka and Storage Class namednginx-stc-cka
. Use the access modeReadWriteOnce
. - Add the created
nginx-pvc-cka
PVC to the existingnginx-pod-cka
POD definition. - Mount the volume claimed by
nginx-pvc-cka
at the path/var/www/html
within thenginx-pod-cka
POD. - Add tolerations with the key
node-role.kubernetes.io/control-plane
set toExists
and effectNoSchedule
to thenginx-pod-cka
Pod - Ensure that the
peach-pod-cka05-str
POD is running and that the Persistent Volume (PV) is successfullybound
.
一个名为
nginx-pod-cka
的Kubernetes pod定义文件。可以使用Yaml。您的任务是对清单文件进行以下修改:
- 创建一个名为
nginx-pvc-cka
的持久卷声明(PVC)。这个PVC应该从现有的名为nginx-pv-cka
的持久卷(PV)和名为nginx-stc-cka
的存储类请求80Mi的存储空间。请使用ReadWriteOnce
访问模式。- 将创建的
nginx-pvc-cka
PVC添加到现有的nginx-pod-cka
POD定义中。- 将nginx-pvc-cka请求的卷挂载到nginx-pod-cka的
/var/www/html
路径。- 使用关键节点node-role.kubernetes添加tolerations 。设置为“Exists”,对
nginx-pod-cka
Pod生效“NoSchedule
”- 确保peach-pod-cka05-str POD正在运行,并且PV (Persistent Volume)已成功绑定。
解题思路
- 切换集群环境
kubectl config use-context kubernetes-admin@kubernetes
- 创建一个名为
nginx-pvc-cka
的PVC资源
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: nginx-pvc-cka spec: volumeName: nginx-pv-cka storageClassName: nginx-stc-cka accessModes: - ReadWriteOnce resources: requests: storage: 80Mi
提交PVC资源,并查看PVC状态
controlplane $ k apply -f nginx-pvc-cak.yaml persistentvolumeclaim/nginx-pvc-cka created controlplane $ k get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE nginx-pvc-cka Bound nginx-pv-cka 100Mi RWO nginx-stc-cka <unset> 10s
- 把PVC资源引用到
nginx-pod-cka
Pod中,资源清单如下:
apiVersion: v1 kind: Pod metadata: name: nginx-pod-cka spec: volumes: - name: pv-storage persistentVolumeClaim: claimName: nginx-pvc-cka tolerations: - key: 'node-role.kubernetes.io/control-plane' operator: 'Exists' effect: 'NoSchedule' containers: - name: my-container image: nginx:latest volumeMounts: - mountPath: "/var/www/html" name: pv-storage
提交清单,并查看Pod的创建情况
controlplane $ k apply -f nginx-pod-cka.yaml pod/nginx-pod-cka created controlplane $ k get pod NAME READY STATUS RESTARTS AGE nginx-pod-cka 1/1 Running 0 11s