There is a way to pre-bind PVs to PVCs today, here is an example showing how:
- 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
- Then create the PVC with the same name:
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: myclaim spec: storageClassName: "" accessModes: - ReadWriteOnce resources: requests: storage: 5Gi
- 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