题干
For this question, please set this context (In exam, diff cluster name)
kubectl config use-context kubernetes-admin@kubernetes
Your task involves setting up storage components in a Kubernetes cluster. Follow these steps:
Step 1: Create a Storage Class named blue-stc-cka with the following properties:
- Provisioner: kubernetes.io/no-provisioner
- Volume binding mode: WaitForFirstConsumer
Step 2: Create a Persistent Volume (PV) named blue-pv-cka with the following properties:
- Capacity: 100Mi
- Access mode: ReadWriteOnce
- Reclaim policy: Retain
- Storage class: blue-stc-cka
- Local path: /opt/blue-data-cka
- Node affinity: Set node affinity to create this PV on controlplane .
Step 3: Create a Persistent Volume Claim (PVC) named blue-pvc-cka with the following properties:
- Access mode: ReadWriteOnce
- Storage class: blue-stc-cka
- Storage request: 50Mi
- The volume should be bound to blue-pv-cka .
您的任务涉及在Kubernetes集群中设置存储组件。遵循以下步骤:
步骤1:创建一个名为blue-stc-cka的存储类,并具有以下属性:
- 提供程序:
kubernetes.io/no-provisioner
- 卷绑定模式:
WaitForFirstConsumer
步骤2:创建一个名为blue-pv-cka的持久卷(PV),其属性如下:
- 容量:
100Mi
- 访问方式:
ReadWriteOnce
- 回收策略:
Retain
- 存储类:blue-stc-cka
- 本地路径:
/opt/blue-data-cka
- 节点亲和性:设置节点亲和性,在控制平面上创建该PV。
步骤3:创建一个名为blue-pvc-cka的持久容量声明(PVC),并具有以下属性:
- 访问方式:ReadWriteOnce
- 存储类:blue-stc-cka
- 存储要求:50Mi
- volume设置为
blue-pv-ck
a。
解题思路
- 切换集群环境
kubectl config use-context kubernetes-admin@kubernetes
- 创建一个名为
blue-stc-cka
的存储类。
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: blue-stc-cka provisioner: kubernetes.io/no-provisioner volumeBindingMode: WaitForFirstConsumer
并提交blue-stc-cka.yam
l资源清单
controlplane $ k apply -f blue-stc-cka.yaml storageclass.storage.k8s.io/blue-stc-cka created
- 创建一个名为
blue-pv-cka
的PV资源,资源清单如下:
apiVersion: v1 kind: PersistentVolume metadata: name: blue-pv-cka spec: storageClassName: blue-stc-cka persistentVolumeReclaimPolicy: Retain capacity: storage: 100Mi accessModes: - ReadWriteOnce local: path: /opt/blue-data-cka nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - controlplane
提交资源清单,如下:
controlplane $ k apply -f blue-pv-cka.yaml persistentvolume/blue-pv-cka created
- 创建一个名为
blue-pvc-cka
的PVC资源,资源清单如下:
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: blue-pvc-cka spec: storageClassName: blue-stc-cka accessModes: - ReadWriteOnce resources: requests: storage: 50Mi volumeName: blue-pv-cka
提交资源清单,如下:
controlplane $ k apply -f blue-pvc-cka.yaml persistentvolumeclaim/blue-pvc-cka created
- 验证结果
controlplane $ k get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE blue-pvc-cka Bound blue-pv-cka 100Mi RWO blue-stc-cka <unset> 29s