Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How fetch all the k8s object which have finalizer attached to it

Tags:

kubernetes

I am trying to delete a namespace but it is in terminating state, I tried removing the finalizer and applying replace but not able to succeed. Below are the steps and error

[root@~]# kubectl replace "/api/v1/namespaces/service-catalog/finalize" -f n.json
namespace/service-catalog replaced
[root@~]#
[root@~]#
[root@~]# k get ns service-catalog
NAME              STATUS        AGE
service-catalog   Terminating   6d21h
[root@~]# k delete ns service-catalog
Error from server (Conflict): Operation cannot be fulfilled on namespaces "service-catalog": The system is ensuring all content is removed from this namespace.  Upon completion, this namespace will automatically be purged by the system.

In the namespace I had created few crd objects and my good guess is those are the thing which are preventing it from deletion. Right now I am not able memorise all the crd object that I created.

Is there a way where I can query all the object with the finalizer: service-catalog?

like image 297
prashant Avatar asked Oct 16 '25 12:10

prashant


1 Answers

I was looking for all the finalizers that were used in our cluster and this worked for me. It checks for all types of objects in all namespaces and returns their finalizers -- you can probably use awk and grep to filter it out for what you're looking for

kubectl get all -o custom-columns=Kind:.kind,Name:.metadata.name,Finalizers:.metadata.finalizers --all-namespaces

Note, this doesn't return the cluster scoped resources

like image 128
Brando Avatar answered Oct 19 '25 05:10

Brando