题干
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 .
解题思路
- 切换集群环境
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-ckapersistentVolumeReclaimPolicy: Retaincapacity:storage: 100MiaccessModes:- ReadWriteOncelocal:path: /opt/blue-data-ckanodeAffinity:required:nodeSelectorTerms:- matchExpressions:- key: kubernetes.io/hostnameoperator: Invalues:- 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-ckaaccessModes:- ReadWriteOnceresources:requests:storage: 50MivolumeName: 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