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
You are responsible for provisioning storage for a Kubernetes cluster. Your task is to create a PersistentVolume (PV), a PersistentVolumeClaim (PVC), and deploy a pod that uses the PVC for shared storage.
Here are the specific requirements:
- Create a PersistentVolume (PV) named my-pv-cka with the following properties:
- Storage capacity: 100Mi
- Access mode: ReadWriteOnce
- Host path: /mnt/data
- Storage class: standard
- Create a PersistentVolumeClaim (PVC) named my-pvc-cka to claim storage from the my-pv-cka PV, with the following properties:
- Storage class: standard
- request storage: 100Mi (less than)
- Deploy a pod named my-pod-cka using the nginx container image.
- Mount the PVC, my-pvc-cka , to the pod at the path /var/www/html . Ensure that the PV, PVC, and pod are successfully created, and the pod is in a Running state.
Note: Binding and Pod might take time to come up, please have patience
您负责为Kubernetes集群提供存储。您的任务是创建一个PersistentVolume
(PV)和一个persistentvolumecclaim
(PVC),并部署一个使用PVC进行共享存储的pod。
具体要求如下:
- 创建一个名为
my-pv-cka
的持久化卷(PV),其属性如下:
- 存储容量:
100Mi
- 访问方式:
ReadWriteOnce
- 主机路径:“
/mnt/data
” - 存储等级:
standard
创建一个名为my-pv-cka
的persistentvolumecclaim
(PVC),从my-pv-cka
PV中声明存储空间,具有以下属性:
- 存储等级:
standard
- 请求存储:
100Mi
(小于) - 使用nginx容器镜像部署一个名为
my-pod-cka
的pod。 - 将
PVC my-pvc-cka
挂载到/var/www/html
路径下的pod
上。确保已成功创建PV
、PVC
和pod
,且pod状态为“Running
”。
注意:绑定和Pod可能需要一些时间,请耐心等待
解题思路
- 切换集群环境
kubectl config use-context kubernetes-admin@kubernetes
- 按照题目的要求编写PV资源清单
apiVersion: v1 kind: PersistentVolume metadata: name: my-pv-cka spec: storageClassName: standard capacity: storage: 100Mi accessModes: - ReadWriteOnce hostPath: path: "/mnt/data"
- 提交PV资源清单
controlplane $ k apply -f pv.yaml persistentvolume/my-pv-cka created controlplane $ k get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS VOLUMEATTRIBUTESCLASS REASON AGE my-pv-cka 100Mi RWO Retain Available standard <unset> 7s
- 按照题目的要求创建PVC资源,内容如下:
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: my-pvc-cka spec: volumeName: my-pv-cka storageClassName: manual accessModes: - ReadWriteOnce resources: requests: storage: 100Mi
- 提交PVC资源清单
controlplane $ k apply -f pvc.yaml persistentvolumeclaim/my-pvc-cka created controlplane $ k get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE my-pvc-cka Bound my-pv-cka 100Mi RWO standard <unset> 3s
- 按照题目的要求编写Pod资源清单,内容如下:
apiVersion: v1 kind: Pod metadata: name: my-pod-cka spec: containers: - name: nginx-container image: nginx volumeMounts: - name: my-pvc-cka-volume mountPath: /var/www/html volumes: - name: my-pvc-cka-volume persistentVolumeClaim: claimName: my-pvc-cka
- 提交Pod资源清单
controlplane $ k apply -f pod.yaml pod/my-pod-cka created