If you have tried to delete a Kubernetes namespace, and it has been hanging in ‘deleting’ for hours on end, it’s likely that you have dangling resources that have not deleted yet.
This will prevent the namespace from being removed.
How to find resources that need to be deleted
You can chain the
api-resources verbs along with a
kubectl get to find dangling resources:
This will run through all API Resources available in your cluster and report if they are found in that namespace.
Now you can simply go and
kubectl delete <resource> to each one as you find them.
A 1-liner to delete the problem namespace
If you are still not able to delete the namespace, then you can use the following 1-liner Python script.
Make sure to replace “