logo

How to reuse a PersistentVolume/PV in Kubernetes

If you’re reading this – you either:

  • sweating as you can’t recover a data from a POD that was using a PV
  • or.. looking for ways to safely delete PODs without affecting storage stored in a PV

Either way, came across the same dilemma while I was migrating my apps to argocd. Took awhile to search for this so I’m documenting for anyone wanted to have the solution. If the PV is already released, skip to number 3

  1. First things first, make sure the PersistentVolume ReclaimPolicy is set to Retain. If it’s currently set to delete, you can easily patch the PV by issuing:
kubectl patch pv <your-pv-name> -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
I was going to redeploy grafana but i want to make sure dashboards are still there

2. Next, proceed to delete the resources that was using it. The status of the PV will then become Release after the PVC/POD holding it is now deleted.

3. In a released state, edit the PV and remove spec.claimRef block

kubectl edit pv <pv name>

4. After removing the spec.claimRef block, the PV will be available. Proceed in re-adding your application

Hope that helps.

Enjoy!

NOTE: Other option is to clone the volume (depends on the storage provider):

https://kubernetes.io/blog/2019/06/21/introducing-volume-cloning-alpha-for-kubernetes/

  1. CooperTNEl Paso Reply

    CooperTNEl Paso

Leave a Reply

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.