Can a PVC be bound to a specific PV?

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
    

Leave a Comment