List all objects from a given namespace using kubectl

7/12/2019

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
-- P Ekambaram
kubectl
kubernetes

2 Answers

7/12/2019

Perhaps you could try this:

kubectl get `kubectl api-resources -o name | tr '\n' ',' | sed 's/.$//'`

Source : Github

-- Malathi
Source: StackOverflow

7/12/2019

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
-- Suresh Vishnoi
Source: StackOverflow