1

I am using widely the helm go sdk. Now i do not know always which resources are still in the cluster and would have a call to completely clean it.

I can get the KubeClient, but found only the delete method expecting the resources.

Maybe the programmatical call to kubectl delete all --all? Best would be including the namespace resource itself.

Or do I need to request the names of all resources and then delete it?

Thank you!

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
Langohr
  • 217
  • 2
  • 10
  • easiest way would be using kubectl command – Amit Baranes May 01 '21 at 09:48
  • Take care. Kubectl get all don’t retrieve all ressources. https://stackoverflow.com/a/53016918/2858926 – XciD May 02 '21 at 07:35
  • Deleting all resources from a Kubernetes cluster, will just break the cluster, you'd be better deleting and re-creating the cluster entirely. If you're creating user resources and want to clean those up, I'd recommend ensuring that all resources are created in a single namespace and then if you can't track the resources, just delete the namespace. – Rory McCune May 11 '21 at 13:20
  • Also if you're using cluster level resources where that won't work, you could add a label to every resource you create and delete all resources with that label. – Rory McCune May 11 '21 at 13:20
  • I solved it not very satisfying by doing a "helm list" and then delete the ressources. As soon a ressource is installed manuelly over kubectl it won't work anymore – Langohr May 15 '21 at 21:31

1 Answers1

0

This is a community wiki answer posted for better visibility. Feel free to expand it.

As already mentioned in the comments, the way to list all the resources would be by using a proper kubectl command. The idea behind it is well explained here:

kubectl api-resources enumerates the resource types available in your cluster.

this means you can combine it with kubectl get to actually list every instance of every resource type in a namespace:

kubectl api-resources --verbs=list --namespaced -o name \
  | xargs -n 1 kubectl get --show-kind --ignore-not-found -l <label>=<value> -n <namespace>

With that you will be able to request names of all the resources and than delete them.

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37