Skip to content
Latchkey

kubectl delete -l: Usage, Options & Common CI Errors

Delete every resource carrying a given label in one command.

kubectl delete -l removes all resources of a type that match a label selector - the idiom for tearing down everything a CI run created when you tagged it consistently. Scoping the selector tightly is what keeps it safe.

What it does

kubectl delete TYPE -l key=value deletes every matching object of that type. Combine selectors with commas for AND (run=ci,pr=42). It honours graceful termination like any delete, and -n scopes it to a namespace; without -n it acts on the current namespace only.

Common usage

Terminal
kubectl delete pods -l app=web
kubectl delete all -l run=ci,pr=${PR_NUMBER}
kubectl delete deploy,svc,cm -l release=preview-${PR_NUMBER}
kubectl delete pods -l app=web --dry-run=client       # preview the match

Common errors in CI

The dangerous mistake is an over-broad or empty selector: a typo that drops the selector entirely turns delete pods -l '' into delete pods (everything in the namespace), so always --dry-run=client the selector first and scope teardown to a dedicated namespace you can simply delete instead. delete all -l does NOT cover every kind - "all" is a curated set (pods, services, deployments, etc.) and misses ConfigMaps, Secrets, PVCs, and CRDs, so a namespace can look empty while those linger. A selector matching nothing prints "No resources found" and exits 0, which can mask a labelling bug.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →