Do Kubernetes persistent volume claims bind again if the persistent volume is being deleted and recreated?

6/9/2016

I have the following pvc (Persistent Volume Claim):

piVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: test-claim-web
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

and the Google Cloud-backed pv (Persistent Volume):

apiVersion: v1
kind: PersistentVolume
metadata:
  name: test-pv-1
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  gcePersistentDisk:
    pdName: test-1
    fsType: ext4

and the Disk in Google cloud that exists.

If I create first the pv and after the pvc, kubectl get pvc,pv will show:

NAME                                STATUS                                VOLUME            CAPACITY     ACCESSMODES              AGE
test-claim-web                      Bound                                 test-pv-1         10Gi         RWO                      15s
NAME                                CAPACITY                              ACCESSMODES       STATUS       CLAIM                    REASON    AGE
test-pv-1                           10Gi                                  RWO               Bound        default/test-claim-web             25s

But if I delete and recreate the pv, kubectl get pvc,pv will show:

NAME                                STATUS                                VOLUME            CAPACITY     ACCESSMODES              AGE
test-claim-web                      Bound                                 test-pv-1         10Gi         RWO                      3m
NAME                                CAPACITY                              ACCESSMODES       STATUS       CLAIM                    REASON    AGE
test-pv-1                           10Gi                                  RWO               Available                                       18s
  • Why is the pvc still Bound?
  • Doesn't the pvc (re-)bind automatically? (I also observed that creating the pv after the pvc makes the pvc wait forever with Pending status.)

I use the following Kubernetes version:

Client Version: version.Info{Major:"1", Minor:"2", GitVersion:"v1.2.4", GitCommit:"3eed1e3be6848b877ff80a93da3785d9034d0a4f", GitTreeState:"clean"}
Server Version: version.Info{Major:"1", Minor:"2", GitVersion:"v1.2.4", GitCommit:"3eed1e3be6848b877ff80a93da3785d9034d0a4f", GitTreeState:"clean"}
-- Gabriel Petrovay
kubernetes
persistent-volume-claims
persistent-volumes

1 Answer

6/10/2016

if I delete and recreate the pv, kubectl get pvc,pv will show [bound]. Why is the pvc still Bound?

That's bug in Kubernetes 1.2, it will be fixed in 1.3. Both PV and PVC should get Bound eventually.

However, deleting a bound PV is very bad idea, as the PVC may be used in a running pod and the pod suddenly looses storage underneath. You should never touch bound PVs!

I also observed that creating the pv after the pvc makes the pvc wait forever with Pending status

It won't wait forever, it should get bound after 10 minutes. Use kube-controller-manager --pvclaimbinder-sync-period=15s to shorten it to 15 seconds. Again, this will be better in Kubernetes 1.3, 15 seconds will be default there.

-- Jan Šafránek
Source: StackOverflow