Error: cannot delete resource
The “cannot delete resource” error means Kubernetes refused deletion because the resource has finalizers or dependencies, leaving it stuck in Terminating.
What It Means
When you run kubectl delete, Kubernetes sets a deletionTimestamp on the resource but doesn’t remove it immediately. Finalizers are hooks that must complete before deletion. If a finalizer cannot finish — or if there’s a protection mechanism — the resource stays in a Terminating state.
Why It Happens
- The resource has finalizers that block deletion (common with custom resources).
- A namespace is stuck in
Terminatingbecause of outstanding resources. - The resource is being used by another resource (e.g. a PVC used by a pod).
- Termination protection is enabled on the resource (cloud-specific).
- The resource controller is not running and can’t process the finalizer.
- A finalizer references a resource that no longer exists.
- The resource has owner references preventing deletion of dependents.
How to Fix It
Step 1: Check the resource for finalizers
kubectl get <resource> <name> -o json | jq '.metadata.finalizers'If the output shows finalizers like kubernetes.io/pv-protection or foregroundDeletion, these are blocking deletion.
Step 2: Remove finalizers
To remove all finalizers and force deletion:
kubectl patch <resource> <name> -p '{"metadata":{"finalizers":[]}}' --type=mergeFor namespaces stuck in Terminating:
kubectl get namespace <stuck-namespace> -o json | jq '.spec = {"finalizers":[]}' > tmp.json
kubectl proxy &
curl -k -H "Content-Type: application/json" -X PUT --data-binary @tmp.json http://localhost:8001/api/v1/namespaces/<stuck-namespace>/finalizeStep 3: Delete dependent resources first
If the resource is being used, delete the dependents beforehand:
# PVC that is mounted by a pod
kubectl delete pod <pod-name>
kubectl delete pvc <pvc-name>
# Service that backs a deployment
kubectl delete deployment <deployment-name>
kubectl delete service <service-name>Step 4: Use force delete
For pods stuck in Terminating:
kubectl delete pod <pod-name> --force --grace-period=0This bypasses the graceful shutdown period and immediately removes the pod from the API server. Use with caution — running containers may be orphaned.
Step 5: Disable termination protection (cloud resources)
For resources behind a load balancer or with termination protection:
# AWS ELB / ALB
aws elb delete-load-balancer --load-balancer-name <name>
aws elbv2 delete-load-balancer --load-balancer-arn <arn>
# Then remove the Kubernetes service
kubectl delete service <service-name>Step 6: Check ownerReferences
kubectl get <resource> <name> -o json | jq '.metadata.ownerReferences'If the resource has an owner that no longer exists, the garbage collector may be stuck. Remove the ownerReference:
kubectl patch <resource> <name> -p '{"metadata":{"ownerReferences":[]}}' --type=mergeBuilt by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro