Created
August 13, 2020 12:50
-
-
Save jossef/a563f8651ec52ad03a243dec539b333d to your computer and use it in GitHub Desktop.
force delete k8s 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
#!/usr/bin/env python3 | |
import atexit | |
import json | |
import requests | |
import subprocess | |
import sys | |
namespace = sys.argv[1] | |
proxy_process = subprocess.Popen(['kubectl', 'proxy']) | |
atexit.register(proxy_process.kill) | |
p = subprocess.Popen(['kubectl', 'get', 'namespace', namespace, '-o', 'json'], stdout=subprocess.PIPE) | |
p.wait() | |
data = json.load(p.stdout) | |
data['spec']['finalizers'] = [] | |
requests.put('http://127.0.0.1:8001/api/v1/namespaces/{}/finalize'.format(namespace), json=data).raise_for_status() |
Yeah, it works like a charm!
It worked on my end. Thanks 👍🏼
worked well Thanks
That worked, thanks
Thanks for sharing, It's worked
Worked well. Thank You.
Very cool, thank you!
little sugar if you need to force delete all "Terminating" namespace at once
kubectl get ns | grep Terminating | awk '{print $1}' | xargs -I '{}' python3 force-delete-k8s-namespace.py {}
Thanks it worked!
wow! really works. Thanks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Much love,
thank you!