Last active
July 27, 2021 17:18
-
-
Save coopbri/349c6b47109904a62ddc4556a60fd97d to your computer and use it in GitHub Desktop.
Forcefully delete a Kubernetes namespace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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