Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing all resources in a namespace

I would like to see all resources in a namespace.

Doing kubectl get all will, despite of the name, not list things like services and ingresses.

If I know the the type I can explicitly ask for that particular type, but it seems there is also no command for listing all possible types. (Especially kubectl get does for example not list custom types).

Any idea how to show all resources before for example deleting that namespace?

like image 539
michas Avatar asked Dec 07 '17 09:12

michas


People also ask

What is the command to list all Kubernetes objects?

The most basic command for viewing Kubernetes objects via kubectl is get . If you run kubectl get <resource-name> you will get a listing of all resources in the current namespace. If you want to get a specific resource, you can use kubectl get <resource-name> <object-name> .


1 Answers

Based on this comment , the supported way to list all resources is to iterate through all the api versions listed by kubectl api-resources:

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> 
like image 60
rcorre Avatar answered Oct 16 '22 19:10

rcorre