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修改后创建

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

    apiVersion: v1
    kind: Pod
    metadata:
    name: test-pvc
    spec:
    containers:
     - name: nginx
       image: nginx
       volumeMounts:
       - mountPath: "/tmp/data"
         name: dev-pvc
    volumes:
     - name: dev-pvc
       persistentVolumeClaim:
         claimName: dev-pvc
    
    # 创建pod
    kubectl apply -f test-pvc.yaml
    

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