1.题目

There is a persistent volume name dev-pv in the cluster, create a persistent volume claim name dev-pvc, make sure this persistent volume claim will bound the persistent volume, and then create a pod name test-pvc that mount this pvc at path /tmp/data, use nginx image.

2.解析

本题目考测pv, pvc。

3.答案

  1. 查看已存在pv dev-pv的信息

    1. kubectl get pv dev-pv -oyaml
    2. kubectl describe pv dev-pv
  2. 拷贝官方文档pvc.yaml,根据已存在pv信息accessModes=ReadWriteOnce, capacity.storage=1Gi修改后创建

    1. apiVersion: v1
    2. kind: PersistentVolumeClaim
    3. metadata:
    4. name: dev-pvc
    5. spec:
    6. accessModes:
    7. - ReadWriteOnce
    8. resources:
    9. requests:
    10. storage: 1Gi
    1. # 创建pvc
    2. kubectl apply -f pvc.yaml
    3. # 查看该pvc是否绑定
    4. kubectl get pvc
  3. 创建pod,拷贝官方文档test-pvc.yaml,根据题意修改yaml

    1. apiVersion: v1
    2. kind: Pod
    3. metadata:
    4. name: test-pvc
    5. spec:
    6. containers:
    7. - name: nginx
    8. image: nginx
    9. volumeMounts:
    10. - mountPath: "/tmp/data"
    11. name: dev-pvc
    12. volumes:
    13. - name: dev-pvc
    14. persistentVolumeClaim:
    15. claimName: dev-pvc
    1. # 创建pod
    2. kubectl apply -f test-pvc.yaml

    https://kubernetes.io/zh/docs/concepts/storage/persistent-volumes/