Listing all resources in a namespace Listing all resources in a namespace kubernetes kubernetes

Listing all resources in a namespace


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>


This may not get all resources but it may be what someone is looking for

kubectl get all,cm,secret,ing -A

This seems to get most of the resources, prefixed with the type.

At least, it gets:

  • pod
  • service
  • daemonset
  • deployment
  • replicaset
  • statefulset
  • job
  • configmap
  • secret
  • ingress

This doesn't get custom resources but does get services.

Else this does something similar:

for i in `kubectl api-resources | awk '{print $1}'` do ; kubectl get $i

Running v1.13


I ended up needing this same functionality due to failed Helm deployments that left remnants in a specific namespace. Here's a function you can put in your bash profile:

function kubectlgetall {  for i in $(kubectl api-resources --verbs=list --namespaced -o name | grep -v "events.events.k8s.io" | grep -v "events" | sort | uniq); do    echo "Resource:" $i    kubectl -n ${1} get --ignore-not-found ${i}  done}

Usage: kubectlgetall <namespace>

Example: get all resources from the kafka namespace:

kubectlgetall kafka