Skip to content

Instantly share code, notes, and snippets.

View imixtron's full-sized avatar
🚀
Moon & Beyond

Imad Ali Khan Abbasi imixtron

🚀
Moon & Beyond
View GitHub Profile
@imixtron
imixtron / delete-unmounted-pvc.sh
Created August 16, 2020 11:45
Delete unmounted pvc's across cluster
# 👏 https://stackoverflow.com/questions/53202727/how-to-delete-only-unmounted-pvcs-and-pvs#answer-59758937
# List Unmounter PVC's
kubectl describe -A pvc | grep -E "^Name:.*$|^Namespace:.*$|^Mounted By:.*$" |\
grep -B 2 "<none>" | grep -E "^Name:.*$|^Namespace:.*$"
# Delete Unmounted PVC's
kubectl describe -A pvc | grep -E "^Name:.*$|^Namespace:.*$|^Mounted By:.*$" |\
grep -B 2 "<none>" | grep -E "^Name:.*$|^Namespace:.*$" | cut -f2 -d: |\
paste -d " " - - | xargs -n2 bash -c 'kubectl -n ${1} delete pvc ${0}'