others-How to solve 'namespace stuck in terminating when delete' problem in kubernetes

1. The purpose of this post

Sometimes, when you delete a resource like namespace in kubernetes, you would find that the resource can not be deleted, it’s stuck in terminating state.

2. Environments

  • docker 19
  • kubernetes 1.17

3. The solution

There must be some resource that is stuck and still reference the namespace, so , check them out:

kubectl api-resources --namespaced=true -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -n <the_namespace> 

Replace the_namespace with the real namespace name.

And then delete the resources like this:

k delete <resource_type> <resource_id> --force --grace-period=0 -n <the_namespace>  

And finally delete the namespace:

k delete namespace <the_namespace>

Now everything works fine.