Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete only unmounted PVCs and PVs?

We don't want to delete PV and PVC as pods reuse them most of the times. However, in the long term, we end up with many PVs' and PVCs' that are not used. How to safely clean?

like image 437
Pav K. Avatar asked Nov 08 '18 06:11

Pav K.


People also ask

How do you force PVC to erase?

Static Volume Provisioning - You have to manually configure the PV, PVC but when you need to delete both PV, PVC then you must start from PVC and then go for PV. Dynamic Volume Provisioning - You have to set up Storage Class along with PVC and Storage Class will take of dynamic provisioning of PV(Persistent Volume).


1 Answers

Not very elegant but bash way to delete Released PV's

kubectl get pv | grep Released | awk '$1 {print$1}' | while read vol; do kubectl delete pv/${vol}; done
like image 153
Pav K. Avatar answered Sep 24 '22 17:09

Pav K.