Forked from unguiculus/force_delete_terminating_namespaces.sh
Created
January 17, 2019 12:48
-
-
Save rimusz/d86bf73638da02b05a91519c3ceca0ff to your computer and use it in GitHub Desktop.
Kubernetes
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
#!/usr/bin/env bash | |
set -e | |
set -o pipefail | |
kubectl proxy & | |
proxy_pid="$!" | |
trap 'kill "$proxy_pid"' EXIT | |
for ns in $(kubectl get namespace --output=jsonpath="{range .items[?(@.status.phase == 'Terminating')]}{@.metadata.name}{'\n'}{end}"); do | |
echo "Removing finalizers from namespace '$ns'..." | |
curl -H "Content-Type: application/json" -X PUT "127.0.0.1:8001/api/v1/namespaces/$ns/finalize" -d @- \ | |
< <(kubectl get namespace "$ns" --output=json | jq '.spec = { "finalizers": [] }') | |
echo | |
echo "Force-deleting namespace '$ns'..." | |
kubectl delete namespace "$ns" --force --grace-period=0 --ignore-not-found=true | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment