Thursday, February 29, 2024
HomeSoftware Engineering Kubernetes Namespace caught in Terminating state

[Solved] Kubernetes Namespace caught in Terminating state

You probably have tried to delete a Kubernetes namespace, and it has been hanging in ‘deleting’ for hours on finish, it’s seemingly that you’ve dangling assets that haven’t deleted but.

$ kubectl get ns
NAME              STATUS        AGE
apps              Energetic        2d19h
default           Energetic        3d8h
my-apps           Terminating   11h

This may stop the namespace from being eliminated.

discover assets that have to be deleted

You possibly can chain the api-resources verbs together with a kubectl get to seek out dangling assets:

kubectl api-resources --verbs=checklist --namespaced -o identify | xargs -n 1 kubectl get --show-kind --show-labels --ignore-not-found -n <your_namespace>

This may run by all API Sources accessible in your cluster and report if they’re present in that namespace.

Now you may merely go and kubectl delete <useful resource> to every one as you discover them.

A 1-liner to delete the issue namespace

If you’re nonetheless not in a position to delete the namespace, then you need to use the next 1-liner Python script.

Be certain to exchange “” together with your namespace itself:

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('{}/finalize'.format(namespace), json=knowledge).raise_for_status()"


Please enter your comment!
Please enter your name here

Most Popular

Recent Comments