Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rimusz/d86bf73638da02b05a91519c3ceca0ff to your computer and use it in GitHub Desktop.
Save rimusz/d86bf73638da02b05a91519c3ceca0ff to your computer and use it in GitHub Desktop.
Kubernetes
#!/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