This script lists all Custom Resource Definitions (CRDs) in a Kubernetes cluster and checks how many instances exist for each CRD. It only prints CRDs that have at least one instance.
- kubectl
- jq
Run the following command in a terminal:
kubectl get crds -o json | jq -r '.items[].metadata.name' | while read crd; do
count=$(kubectl get "$crd" --no-headers 2>/dev/null | wc -l)
if [ "$count" -gt 0 ]; then
echo "$crd: $count"
fi
done