kubectl-plugins

orphans

Find unused ConfigMaps, Secrets, PVCs and Services with no endpoints.

Install kubectl-orphans
curl -fsSL https://kubectl-plugins.dev/install.sh | sh -s -- orphans
Download a binary insteadmacOS (Apple silicon) · macOS (Intel) · Linux (amd64) · Linux (arm64) · Windows (amd64)
Put the binary on your PATH as kubectl-orphans, or build from source.
kubectl orphans [-n NAMESPACE | -A] [--type configmaps,secrets,pvcs,services]

Reports resources that look unused, which is handy for cleanup:

Service account token Secrets, Helm release Secrets and kube-root-ca.crt are skipped.

Flags

FlagDescription
-n, --namespaceNamespace to scan (default: current context namespace)
-A, --all-namespacesScan every namespace and add a NAMESPACE column
--typeComma-separated types to check (default: all four)

Examples

kubectl orphans
kubectl orphans -A
kubectl orphans --type secrets,pvcs
kubectl orphans -n staging --type services

Sample output

$ kubectl orphans -A
NAMESPACE   KIND      NAME             REASON
default     ConfigMap old-settings     not referenced by any pod
default     PVC       data-old-0       not mounted by any pod
staging     Secret    legacy-api-key   not referenced by any pod
staging     Service   canary           no ready endpoints

Prints No orphaned resources found. when everything is in use. Once you have reviewed the list, delete with kubectl delete, for example kubectl delete pvc data-old-0 -n default.

Only running pods are checked, so resources used solely by scaled-to-zero workloads or CronJobs between runs are reported too. Review before deleting.