Useful Resources: Persistent Volumes & Claim
题干
For this question, please set this context (In exam, diff cluster name)
kubectl config use-context kubernetes-admin@kubernetes
Create a PersistentVolume (PV) and a PersistentVolumeClaim (PVC) using an existing storage class named gold-stc-cka to meet the following requirements:
Step 1: Create a Persistent Volume (PV)
- Name the PV as gold-pv-cka .
- Set the capacity to 50Mi .
- Use the volume type hostpath with the path /opt/gold-stc-cka .
- Assign the storage class as gold-stc-cka .
- Ensure that the PV is created on node01 , where the /opt/gold-stc-cka directory already exists.
- Apply a label to the PV with key tier and value white .
Step 2: Create a Persistent Volume Claim (PVC)
- Name the PVC as gold-pvc-cka .
- Request 30Mi of storage from the PV gold-pv-cka using the matchLabels criterion.
- Use the gold-stc-cka storage class.
- Set the access mode to ReadWriteMany .
使用现有的存储类gold-stc-cka
创建一个PersistentVolume
(PV)和一个persistentvolumecclaim
(PVC),以满足以下要求:
步骤1:创建持久卷(PV)
- 将PV命名为
gold-pv-cka
。 - 设置容量为50Mi。
- 使用卷类型的主机路径,路径为
/opt/gold-stc-cka
。 - 将存储类指定为
gold-stc-cka
。 - 确保PV创建在node01上,且
/opt/gold-stc-cka
目录已经存在。 - 为PVC添加标签,键为
tier
,值white
步骤2:创建持久容量声明(PVC)
- 将PVC命名为
gold-pvc-cka
。 - 使用
matchLabels
标准从PVgold-pv-cka
请求30Mi的存储空间。 - 使用
gold-stc-cka
存储类。 - 设置读写模式为“读写多”。
解题思路
- 切换k8s集群环境
kubectl config use-context kubernetes-admin@kubernetes
- 创建一个PV资源,资源清单如下
apiVersion: v1 kind: PersistentVolume metadata: labels: tier: white name: gold-pv-cka spec: nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - node01 storageClassName: gold-stc-cka capacity: storage: 50Mi accessModes: - ReadWriteMany hostPath: path: "/opt/gold-stc-cka"
提交PV资源清单,并查看创建情况
persistentvolume/gold-pv-cka created controlplane $ k get pv -o wide NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS VOLUMEATTRIBUTESCLASS REASON AGE VOLUMEMODE gold-pv-cka 50Mi RWX Retain Available gold-stc-cka <unset> 5s Filesystem
- 按照题目的要求创建PVC,资源清单如下
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: gold-pvc-cka spec: selector: matchLabels: tier: white storageClassName: gold-stc-cka accessModes: - ReadWriteMany resources: requests: storage: 30Mi
提交PV资源清单,并查看创建情况
controlplane $ k apply -f pvc.yaml persistentvolumeclaim/gold-pvc-cka created controlplane $ k get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE gold-pvc-cka Bound gold-pv-cka 50Mi RWX gold-stc-cka <unset> 17s