Skip to content

Instantly share code, notes, and snippets.

@jossef
Created August 13, 2020 12:50
Show Gist options
  • Save jossef/a563f8651ec52ad03a243dec539b333d to your computer and use it in GitHub Desktop.
Save jossef/a563f8651ec52ad03a243dec539b333d to your computer and use it in GitHub Desktop.
force delete k8s namespace
#!/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()
@achintyx2
Copy link

Thanks it worked!

@marcelomrwin
Copy link

wow! really works. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment