模拟题目

设置配置环境:

kubectl config use-context ok8s

Task

创建一个新的 PersistentVolumeClaim :

  • 名称: pv-volume
  • Class: csi-hostpath-sc
  • 容量: 10Mi

创建一个新的 Pod ,来将 PersistentVolumeClaim 作为 volume 进行挂载:

  • 名称:web-server
  • Image:nginx:1.16
  • 挂载路径:/usr/share/nginx/html
  • 配置新的Pod,以对 volume 具有 ReadWriteOnce 权限。

最后,使用 kubectl editkubectl patch 将 PersistentVolumeClaim 的容量扩展为 70Mi ,并记录此更改。


参考

任务 –> 配置 Pods 和容器 –> 配置 Pod 以使用 PersistentVolume 作为存储
https://kubernetes.io/zh-cn/docs/tasks/configure-pod-container/configure-persistent-volume-storage/


解答

考试的时候务必记住切换集群, 注意集群名称 kubectl config use-context k8s

vim pvc.yaml

pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pv-volume #pvc名字
spec:
storageClassName: csi-hostpath-sc # class名
accessModes:
- ReadWriteOnce # 注意,考试时的访问模式可能有ReadWriteMany和ReadOnlyMany和ReadWriteOnce,根据题目要求写。
resources:
requests:
storage: 10Mi # 大小
kubectl apply -f pvc.yaml
vim pvc-pod.yaml

pvc-pod.yaml

apiVersion: v1
kind: Pod
metadata:
name: web-server
spec:
volumes:
- name: task-pv-storage # 两处name需要一样
persistentVolumeClaim:
claimName: pv-volume # 这个要使用上面创建的pvc名字
containers:
- name: nginx
image: nginx:1.16 # 使用指定镜像
volumeMounts:
- mountPath: "/usr/share/nginx/html" # 挂载容器内位置
name: task-pv-storage # 两处name需要一样
kubectl apply -f pvc-pod.yaml

修改PVC配置

kubectl edit pvc pv-volume --record

修改 大小 70Mi

create-pvc-0


检查
kubectl get pvc
kubectl get pod web-server