Skip to content

Instantly share code, notes, and snippets.

@coopbri
Last active July 27, 2021 17:18
Show Gist options
  • Save coopbri/349c6b47109904a62ddc4556a60fd97d to your computer and use it in GitHub Desktop.
Save coopbri/349c6b47109904a62ddc4556a60fd97d to your computer and use it in GitHub Desktop.
Forcefully delete a Kubernetes namespace
#!/bin/sh
# Forcefully delete a Kubernetes namespace.
if [[ $# -eq 0 ]]; then
echo $'[ERROR] No namespace specified, please specify one \n\n Usage: ./force-delete-namespace.sh [namespace]'
exit 0
fi
# get namespace JSON
kubectl get ns $1 -o json >tmp_$1.json
# remove 'kubernetes' from spec.finalizers
sed -i 's/"kubernetes"//g' tmp_$1.json
# inject new spec
kubectl replace --raw "/api/v1/namespaces/$1/finalize" -f ./tmp_$1.json
# remove temporary JSON file
rm tmp_$1.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment