Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all objects from a given namespace using kubectl

I would like to list all objects that are present in a specific namespace in kubernetes.

kubectl get all -n <namespace>

the above command doesn't list all available objects from the given namespace. Is there a way to list them using kubectl?

i can list all objects that i want by passing them to kubectl. but i dont want that.

kubectl -n <namespace> get deployment,rs,sts,ds,job,cronjobs -oyaml
like image 409
P Ekambaram Avatar asked Oct 16 '22 13:10

P Ekambaram


People also ask

What command is used to list all Kubernetes objects in all namespaces?

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> .


2 Answers

First of all these following rules decide if the resource will be part of the all Category or not.

Here are the rules to add a new resource to the kubectl get all output.

  • No cluster scoped resources

  • No namespace admin level resources (limits, quota, policy,
    authorization rules)

  • No resources that are potentially unrecoverable (secrets and pvc)

  • Resources that are considered "similar" to #3 should be grouped the
    same (configmaps)

To Answer your question This is taken from rcorre's Answer

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

Lastly, If you want to add a Custom Resource in all category, you need to provide these field in your CRD spec. custom-resource-definitions:categories

# categories is a list of grouped resources the custom resource belongs to.
    categories:
    - all

like image 175
Suresh Vishnoi Avatar answered Oct 19 '22 02:10

Suresh Vishnoi


Try:

kubectl -n your_namespace get all
like image 21
annac Avatar answered Oct 19 '22 02:10

annac