Skip to content

Instantly share code, notes, and snippets.

@nitinsatish
Created August 9, 2022 11:50
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 nitinsatish/8f79d8ba58c4daeb8211ed85318f0459 to your computer and use it in GitHub Desktop.
Save nitinsatish/8f79d8ba58c4daeb8211ed85318f0459 to your computer and use it in GitHub Desktop.
[Delete terminating namespace] #k8s
#!/usr/bin/env bash
function delete_namespace () {
echo "Deleting namespace $1"
kubectl get namespace $1 -o json > tmp.json
sed -i 's/"kubernetes"//g' tmp.json
kubectl replace --raw "/api/v1/namespaces/$1/finalize" -f ./tmp.json
rm ./tmp.json
}
TERMINATING_NS=$(kubectl get ns | awk '$2=="Terminating" {print $1}')
for ns in $TERMINATING_NS
do
delete_namespace $ns
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment