How to delete only unmounted PVCs and PVs?

Pav K. picture Pav K. · Nov 8, 2018 · Viewed 8.6k times · Source

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?

Answer

Pav K. picture Pav K. · Dec 4, 2019

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