Skip to content

Instantly share code, notes, and snippets.

@bohrasd
Created January 21, 2023 03:43
Show Gist options
  • Save bohrasd/4769035b7aa670cf7382aee837ec9223 to your computer and use it in GitHub Desktop.
Save bohrasd/4769035b7aa670cf7382aee837ec9223 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Remove terminating namespaces
# Usage: ./remove-terminating-ns.sh
TERMINATING_NS=$(kubectl get ns | grep Terminating | awk '{print $1}')
kubectl proxy &
PROXY_PID=$!
for ns in $TERMINATING_NS; do
echo "Removing namespace $ns"
kubectl get ns $ns -o json > $ns.json
sed -i -e 's/"kubernetes"//g' $ns.json
curl -k -H "Content-Type: application/json" -X PUT --data-binary @$ns.json http://localhost:8001/api/v1/namespaces/$ns/finalize
kubectl delete ns $ns
rm $ns.json
done
kill $PROXY_PID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment