Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes: How do I delete PV in the correct manner

The stateful set es-data was failing on our test environment and I was asked to delete corresponding PV.

So I deleted the following for es-data: 1) PVC 2) PV They showed as terminating and was left for the weekend. Upon arriving this morning they still showed as terminating so deleted both PVC and PV forcefully. No joy. To fix the whole thing I had to delete the stateful set.

Is this correct if you wanted to delete the PV?

like image 718
mac Avatar asked Feb 11 '19 11:02

mac


People also ask

Does deleting PVC delete PV?

Reclaiming a persistent volume manuallyWhen a persistent volume claim (PVC) is deleted, the persistent volume (PV) still exists and is considered "released".

How do I delete all PVC in a namespace?

kubectl delete pod --all / pod-name. kubectl delete pvc --all / pvc-name. kubectl delete pv --all / pv-name.


2 Answers

You can delete the PV using following two commands:

kubectl delete pv <pv_name> --grace-period=0 --force 

And then deleting the finalizer using:

kubectl patch pv <pv_name> -p '{"metadata": {"finalizers": null}}' 
like image 104
Prafull Ladha Avatar answered Sep 24 '22 22:09

Prafull Ladha


Firstly run kubectl patch pv {PVC_NAME} -p '{"metadata":{"finalizers":null}}'

then run kubectl delete pv {PVC_NAME}

like image 32
Sunil Pandey Avatar answered Sep 22 '22 22:09

Sunil Pandey