Can a PVC be bound to a specific PV?

后端 未结 7 1276
一生所求
一生所求 2020-11-29 02:34

This was discussed by k8s maintainers in https://github.com/kubernetes/kubernetes/issues/7438#issuecomment-97148195:

Allowing users to ask f

7条回答
  •  春和景丽
    2020-11-29 02:50

    There is a way to pre-bind PVs to PVCs today, here is an example showing how:

    1. Create a PV object with a ClaimRef field referencing a PVC that you will subsequently create:
       $ kubectl create -f pv.yaml
       persistentvolume "pv0003" created
      
      where pv.yaml contains:
       apiVersion: v1
       kind: PersistentVolume
       metadata:
         name: pv0003
       spec:
         storageClassName: ""
         capacity:
           storage: 5Gi
         accessModes:
           - ReadWriteOnce
         persistentVolumeReclaimPolicy: Retain
         claimRef:
           namespace: default
           name: myclaim
         nfs:
           path: /tmp
           server: 172.17.0.2
      
    2. Then create the PVC with the same name:
       kind: PersistentVolumeClaim
       apiVersion: v1
       metadata:
         name: myclaim
       spec:
         storageClassName: ""
         accessModes:
           - ReadWriteOnce
         resources:
           requests:
             storage: 5Gi
      
    3. The PV and PVC should be bound immediately:
       $ kubectl get pvc
       NAME      STATUS    VOLUME    CAPACITY   ACCESSMODES   AGE
       myclaim   Bound     pv0003    5Gi        RWO           4s
       $ ./cluster/kubectl.sh get pv
       NAME      CAPACITY   ACCESSMODES   STATUS    CLAIM             REASON    AGE
       pv0003    5Gi        RWO           Bound     default/myclaim             57s
      

提交回复
热议问题