Stuck in Terminating state!

  • 7 September 2023
  • 8 comments
  • 101 views

Userlevel 7
Badge +22

Hi Everyone,

 

I don’t remember if this has come up here before but every once in a while when deleting namespaces your deletion just hangs in a terminating state:

Where is the Terminator

Yes I am removing Kasten but only because this is a test lab for other purposes. Never delete Kasten in production if you want data protection 😉

So what is up?  I had installed via helm so this would normally not happen but I think I was tinkering and there may have been so objects left over. We can check that by running this command:

kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get -n kasten-io
Nothing found

No objects are present which is good since we don’t want to junk lying around in the cluster.

The problem when this happens is that a finalizer is present for whatever reason so you need to manually remove it. We can get the namespace manifest and check it out:

kubectl get ns kasten-io -o json >kasten.json

Let’s view the file:

There it is

We need to remove this in order for the deletion to continue.

Edit the file and remove the “kubernetes” line

The file should now look like this:

Edited File

Now we need to replace this in the cluster:

kubectl replace --raw "/api/v1/namespaces/kasten-io/finalize" -f kasten.json

You will see a lot of output from that command:

output

Now when we look for the kasten-io namespace we see that it is gone:

Gone

You may be asking just what are finalizers? In short they are there to tell system to wait while everything gets cleaned up in the namespace before deleting it. You can find a deeper dive on finalizers over on the Kubernetes official documentation page:

 

https://kubernetes.io/docs/concepts/overview/working-with-objects/finalizers/


8 comments

Userlevel 7
Badge +17

Nice write-up Geoff. Easy workaround to get the job done at least. Thanks for sharing!

Userlevel 7
Badge +20

Another great Kubernetes tidbit Geoff.  👍🏼

Userlevel 7
Badge +6

The quickest option is going to be helm uninstall even in test and demo environments. 
 

 

Userlevel 5
Badge +3

There is probably some CRDs that were not cleaned up hence the finalizer getting stuck, and by removing the finalizer, they’ll still be there. Be interesting to know if that is the case, I know I’ve come across it before.

Userlevel 7
Badge +22

The quickest option is going to be helm uninstall even in test and demo environments. 
 

 

yup helm was used but.. I am trying to remember what I did “extra” on this install :) It is an old Linux laptop and I was tampering ;)

Userlevel 7
Badge +22

There is probably some CRDs that were not cleaned up hence the finalizer getting stuck, and by removing the finalizer, they’ll still be there. Be interesting to know if that is the case, I know I’ve come across it before.

I should have mentioned that I did take a peak at that too 

CRD

Unless they were not showing up. But great point, CRD’s need to be checked. 

Userlevel 7
Badge +22

I wonder if the garbage collector in that case (left over objects) would have cleaned those up? 

 

https://kubernetes.io/docs/concepts/architecture/garbage-collection/

Userlevel 2

kubectl get crd |grep kio | awk '{print $1}'| xargs kubectl delete crd 

kubectl get apiservices |grep kio | awk '{print $1}'| xargs kubectl delete apiservices

kubectl get crd |grep kanister | awk '{print $1}'| xargs kubectl delete crd 

kubectl get apiservices |grep kanister | awk '{print $1}'| xargs kubectl delete apiservices

kubectl get apiservices |grep kanister | awk '{print $1}'| xargs kubectl delete apiservices

Comment