Kubernetes PVC Reclaim Policy Tutorial

Kubernetes PVC Reclaim Policy Tutorial

Reclaim Policy

The reclaim policy is responsible for what happens to the data in persistent volume when the kubernetes persistent volume claim has been deleted.

Reclaim Policies

A Persistent Volume can have several different reclaim policies

Retain:

If this policy is enabled, the PV will continue to exist even after the PVC is deleted. When the claim is deleted, the volume remains. but it won’t be available to another claim until the previous claimant’s data remains on the volume. With the “Retain” policy, if a user deletes a PersistentVolumeClaim the corresponding PersistentVolume is not be deleted. Instead, it is moved to the Released phase, where all of its data can be manually recovered.

Delete:

The persistent volume is deleted when the claim is deleted. For dynamically provisioned PersistentVolumes, the default reclaim policy is “Delete”. This reclaim policy deletes the PersistentVolume  object from the Kubernetes API and associated storage capacity in the external infrastructure (e.g., AWS EBS, Google Persistent Disk, etc.). AWS EBS, GCE PD, Azure Disk, and Cinder volumes support this delete reclaim policy.

PersistentVolumes can have various reclaim policies, including “Retain” and “Delete”. For dynamically provisioned PersistentVolumes, the default reclaim policy is “Delete”. This means that a dynamically provisioned volume is automatically deleted when a user deletes the corresponding PersistentVolumeClaim. This automatic behavior might be inappropriate if the volume contains precious data. In that case, it is more appropriate to use the “Retain” policy.

Kubernetes Pvc Reclaim Policy Example

i have one pv and pvc in my cluster. you can create these pv and pvc from persistent volumes tutorial.

master $ kubectl get pv

NAME   CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM           STORAGECLASS   REASON   AGE
mypv   5Gi        RWO            Retain           Bound    default/mypvc                           33s

master $ kubectl get pvc

NAME    STATUS   VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
mypvc   Bound    mypv     5Gi        RWO                           11s

you can see in above ‘CLAIM’ section in pv, that mpyvpc(pvcname) is attched to mypv(pvname).

Lets delete the PVC

master $ kubectl delete pvc mypvc

persistentvolumeclaim "mypvc" deleted

Verify the status of pv

master $ kubectl get pv
NAME   CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS     CLAIM           STORAGECLASS   REASON   AGE
mypv   5Gi        RWO            Retain           Released   default/mypvc                           61m

Here you can see the status has been changed from bound to released but mypvc is attached to pv in CLAIM section.

  • Kubernetes Pvc Reclaim Policy
  • Kubernetes Pvc Reclaim Policy
  • Kubernetes Persistent volume Reclaim Policy
  • Pvc Reclaim Policy
  • Persistent volume Reclaim Policy

Leave a Reply

Your email address will not be published. Required fields are marked *