Useful Resources: Storage Classes , Persistent Volumes Claim , Pods
题干
For this question, please set this context (In exam, diff cluster name)
kubectl config use-context kubernetes-admin@kubernetes
- Create a Storage Class named fast-storage with a provisioner of kubernetes.io/no-provisioner and a volumeBindingMode of Immediate .
- Create a Persistent Volume (PV) named fast-pv-cka with a storage capacity of 50Mi using the fast-storage Storage Class with ReadWriteOnce permission and host path /tmp/fast-data .
- Create a Persistent Volume Claim (PVC) named fast-pvc-cka that requests 30Mi of storage from the fast-pv-cka PV(using the fast-storage Storage Class).
- Create a Pod named fast-pod-cka with nginx:latest image that uses the fast-pvc-cka PVC and mounts the volume at the path /app/data .
- 使用
kubernetes.io/no-provision
提供程序创建一个名为fast-storage
的存储类。volumeBindingMode
为Immediate
。- 创建一个名为
fast-pv-cka
的持久卷,存储容量为50Mi
,使用fast-storage
存储类,具有ReadWriteOnce
权限,主机路径为/tmp/fast-data
。- 创建一个名为
fast-pvc-cka
的持久卷声明(PVC),它从fast-pv-cka
PV请求30Mi
的存储空间(使用fast-storage存储类)。- 使用
nginx:latest
镜像创建一个名为fast-pod-cka
的Pod,使用fast-pvc-cka
PVC并将卷挂载到/app/data
路径。
解题思路
- 创建一个名为
fast-storage
的Storage CLass。资源清单如下:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: fast-storage
provisioner: kubernetes.io/no-provisioner
reclaimPolicy: Retain
allowVolumeExpansion: true
volumeBindingMode: Immediate
- 提交fast-storage.yaml资源清单,如下
controlplane $ k apply -f fast-storage.yaml
storageclass.storage.k8s.io/fast-storage created
- 创建一个名为
fast-pv-cka
的PV,资源清单如下:
apiVersion: v1
kind: PersistentVolume
metadata:
name: fast-pv-cka
spec:
storageClassName: fast-storage
capacity:
storage: 50Mi
accessModes:
- ReadWriteOnce
hostPath:
path: "/tmp/fast-data"
- 提交
fast-pv-cka.yaml
资源清单,如下
controlplane $ k apply -f fast-pv-cka.yaml
persistentvolume/fast-pv-cka created
- 创建一个名为
fast-pvc-cka
的PV,资源清单如下:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: fast-pvc-cka
spec:
storageClassName: fast-storage
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 30Mi
- 提交
fast-pvc-cka.yaml
资源清单,如下
controlplane $ k apply -f fast-pvc-cka.yaml
persistentvolumeclaim/fast-pvc-cka created
- 创建一个名为
fast-pod-cka
的pod,资源清单如下:
apiVersion: v1
kind: Pod
metadata:
name: fast-pod-cka
spec:
volumes:
- name: pv-storage
persistentVolumeClaim:
claimName: fast-pvc-cka
containers:
- name: nginx-container
image: nginx:latest
volumeMounts:
- mountPath: "/app/data"
name: pv-storage
- 提交
fast-pod-cka.yaml
资源清单,如下
controlplane $ k apply -f fast-pod-cka.yaml
pod/fast-pod-cka created
- 验证结果
controlplane $ k get pod
NAME READY STATUS RESTARTS AGE
fast-pod-cka 1/1 Running 0 38s