Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to do with Released persistent volume?

TL;DR. I'm lost as to how to access the data after deleting a PVC, as well as why PV wouldn't go away after deleting a PVC.

Steps I'm taking:

  1. created a disk in GCE manually:

    gcloud compute disks create --size 5Gi disk-for-rabbitmq --zone europe-west1-b 
  2. ran:

    kubectl apply -f /tmp/pv-and-pvc.yaml 

    with the following config:

    # /tmp/pv-and-pvc.yaml apiVersion: v1 kind: PersistentVolume metadata:   name: pv-for-rabbitmq spec:   accessModes:   - ReadWriteOnce   capacity:     storage: 5Gi   gcePersistentDisk:     fsType: ext4     pdName: disk-for-rabbitmq   persistentVolumeReclaimPolicy: Delete   storageClassName: standard --- apiVersion: v1 kind: PersistentVolumeClaim metadata:   name: pvc-for-rabbitmq spec:   accessModes:   - ReadWriteOnce   resources:     requests:       storage: 5Gi   storageClassName: standard   volumeName: pv-for-rabbitmq 
  3. deleted a PVC manually (on a high level: I'm simulating a disastrous scenario here, like accidental deletion or misconfiguration of a helm release):

    kubectl delete pvc pvc-for-rabbitmq 

At this point I see the following:

$ kubectl get pv NAME              CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS     CLAIM                      STORAGECLASS   REASON   AGE pv-for-rabbitmq   5Gi        RWO            Delete           Released   staging/pvc-for-rabbitmq   standard                8m $ 

A side question, just improve my understanding: why PV is still there, even though it has a reclaim policy set to Delete? Isn't this what the docs say for the Delete reclaim policy?

Now if I try to re-create the PVC to regain access to the data in PV:

$ kubectl apply -f /tmp/pv-and-pvc.yaml persistentvolume "pv-for-rabbitmq" configured persistentvolumeclaim "pvc-for-rabbitmq" created $ 

I still get this for pvs, e.g. a PV is stuck in Released state:

$ kubectl get pv NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS     CLAIM                             STORAGECLASS   REASON    AGE pv-for-rabbitmq                            5Gi        RWO            Delete           Released   staging/pvc-for-rabbitmq          standard                 15m $ 

...and I get this for pvcs:

$ kubectl get pvc NAME               STATUS    VOLUME            CAPACITY   ACCESS MODES   STORAGECLASS   AGE pvc-for-rabbitmq   Pending   pv-for-rabbitmq   0                         standard       1m $ 

Looks like my PV is stuck in Released status, and PVC cannot access the PV which is not in Available status.

So, why the same PV and PVC cannot be friends again? How do I make a PVC to regain access to data in the existing PV?

like image 490
gmile Avatar asked Jun 03 '18 14:06

gmile


People also ask

What happens if PVC is deleted?

Storage Object in Use Protection If a user deletes a PVC that is in active use by a pod, the PVC is not removed immediately. PVC removal is postponed until the PVC is no longer actively used by any pods. Also, if a cluster admin deletes a PV that is bound to a PVC, the PV is not removed immediately.

Does deleting PVC delete data?

In case of Delete, the PV is deleted automatically when the PVC is removed, and the data on the PVC will also be lost.


1 Answers

kubectl patch pv pv-for-rabbitmq -p '{"spec":{"claimRef": null}}' 

This worked for me.

like image 96
Bharat Chhabra Avatar answered Sep 21 '22 15:09

Bharat Chhabra