Skip to content

Instantly share code, notes, and snippets.

@ybelleguic
Created April 15, 2021 09:43
Show Gist options
  • Save ybelleguic/575cc8a6021acad5855a9e0108075b7a to your computer and use it in GitHub Desktop.
Save ybelleguic/575cc8a6021acad5855a9e0108075b7a to your computer and use it in GitHub Desktop.
Cleanup k8s namespace
#From https://stackoverflow.com/questions/52369247/namespace-stuck-as-terminating-how-do-i-remove-it#:~:text=This%20is%20caused%20by%20resources,controller%20is%20unable%20to%20remove.&text=You%20can%20edit%20namespace%20on,enter%20or%20save%2Fapply%20changes.
function cleanup-ns() {
NS=$1
kubectl get namespace $NS -o json \
| tr -d "\n" | sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/" \
| kubectl replace --raw /api/v1/namespaces/$NS/finalize -f -
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment