P Ekambaram
P Ekambaram

Reputation: 17615

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

Upvotes: 6

Views: 10777

Answers (4)

Faizan Noor
Faizan Noor

Reputation: 736

For listing all the objects in your namespace:

kubectl get all -n=<namespace>

Upvotes: 1

annac
annac

Reputation: 15

Try:

kubectl -n your_namespace get all

Upvotes: -1

Suresh Vishnoi
Suresh Vishnoi

Reputation: 18353

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

Upvotes: 4

Malathi
Malathi

Reputation: 2195

Perhaps you could try this:

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

Source : Github

Upvotes: 0

Related Questions