Skip to content

Instantly share code, notes, and snippets.

@imixtron
Created August 16, 2020 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imixtron/4c9a588ba094c313308289b2dcea9c39 to your computer and use it in GitHub Desktop.
Save imixtron/4c9a588ba094c313308289b2dcea9c39 to your computer and use it in GitHub Desktop.
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}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment