Listing All Resources in Kubernetes

Two quick and easy options of listing all the resources deployed in Kubernetes.

Setting a default namespace (optional):
kubectl config set-context --current --namespace=my-namespace

Option 1

# Listing all the standard (pod, service, etc.) k8s resources in specific namespace
kubectl get all -n my-namespace
# Listing all the standard k8s resources in current context's default namespace
kubectl get all

Option 2:

Or you can use function below. Advantage is that this function will list default resources and Custom Resources (CRDs) as well:

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
    
    if [ -z "$1" ]
    then
        kubectl get --ignore-not-found ${i}
    else
        kubectl -n ${1} get --ignore-not-found ${i}
    fi
  done
}

Usage: kubectlgetall <namespace>

namespace is optional

Example: get all resources from the kafka namespace:

kubectlgetall kafka

get all resources from default namespace:

kubectlgetall


References:

For any feedback or request, don't hesitate, open an `issue` and let me know. Don't be shy.