kubectl delete: Usage, Options & Common CI Errors
Remove resources - and survive the finalizer that hangs the delete.
kubectl delete removes objects by name, by label selector, or by the same manifest you applied. In CI it powers teardown jobs, where scoping and timeouts matter.
What it does
kubectl delete sends a delete request and, by default, waits for graceful termination (the object's terminationGracePeriodSeconds). You can target a name, a -l selector, a -f manifest, or --all within a namespace. --grace-period and --force control how aggressively termination happens.
Common usage
kubectl delete pod my-pod
kubectl delete -f manifests/ # everything in those files
kubectl delete pods -l app=web # by label
kubectl delete deploy web --wait=false # do not block on teardown
kubectl delete pod stuck --grace-period=0 --forceCommon errors in CI
A delete that "hangs forever" in CI is almost always a finalizer: the object enters Terminating but a controller has not removed its finalizer, so kubectl blocks until your step times out. Check with kubectl get <obj> -o jsonpath='{.metadata.finalizers}'. The dangerous workaround - kubectl patch ... -p '{"metadata":{"finalizers":null}}' - orphans whatever the finalizer was cleaning up, so only do it for known-stuck test fixtures. Also beware --all with a missing -n: it deletes everything in the default namespace. Always scope teardown to a dedicated namespace and delete that namespace instead.