When you’ve got tried to delete a Kubernetes namespace, and it has been hanging in ‘deleting’ for hours on finish, it’s doubtless that you’ve dangling assets that haven’t deleted but.
$ kubectl get ns
NAME STATUS AGE
apps Lively 2d19h
default Lively 3d8h
my-apps Terminating 11h
This may stop the namespace from being eliminated.
The way to discover assets that have to be deleted
You’ll be able to chain the api-resources
verbs together with a kubectl get
to seek out dangling assets:
kubectl api-resources --verbs=listing --namespaced -o title | xargs -n 1 kubectl get --show-kind --show-labels --ignore-not-found -n <your_namespace>
This may run via all API Sources out there in your cluster and report if they’re present in that namespace.
Now you’ll be able to merely go and kubectl delete <useful resource>
to every one as you discover them.
A 1-liner to delete the issue namespace
In case you are nonetheless not in a position to delete the namespace, then you should utilize the next 1-liner Python script.
Make sure that to switch “
python3 -c "namespace='<my-namespace>';import atexit,subprocess,json,requests,sys;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();knowledge = json.load(p.stdout);knowledge['spec']['finalizers'] = [];requests.put('http://127.0.0.1:8001/api/v1/namespaces/{}/finalize'.format(namespace), json=knowledge).raise_for_status()"