Skip to main content
Kubernetes internalsLesson 3 of 12

Deletion Is More Complex Than You Think

In Kubernetes, a "delete" request does not make an object vanish at once. If cleanup work remains, it waits, and dependent objects are removed afterward by another worker. Let's follow why Terminating lingers in kubectl get.

DeletingPVC data
StateDelete requested
Finalizers left—
Namespace · shopUserkubectlAPI serverhandles deletesGCgarbage collectorDeploymentwebReplicaSetweb-7d9f8c6b5web Podowner: RSBackupCR from a toolPVCdataOperatorbackup tooldelete pvc
RequestResponse / report

What you will learn

  • How deletionTimestamp and finalizers relate
  • Terminating means "waiting"
  • Owner references and garbage collection
  • Why namespace deletion never finishes

Common finalizers and when they get stuck​

FinalizerWhat it waits forWhen it stays stuck
kubernetes.io/pvc-protectionNo Pod using this PVCA Pod that mounts the PVC is still alive
kubernetes.io/pv-protectionNo PVC bound to this PVThe PVC still exists
kubernetes on a namespaceEvery object in the namespace deletedOne object inside is stuck on a finalizer
Names added by each toolThe tool cleaning up its external resourcesThe tool's controller was removed or stopped

Try it yourself​

kubectl get pvc -A -o custom-columns=NAME:.metadata.name,FINALIZERS:.metadata.finalizers # pvc-protection on every PVC
kubectl get <kind> <name> -n <namespace> -o jsonpath='{.metadata.deletionTimestamp} {.metadata.finalizers}' # Terminating: when, and waiting on what
kubectl get pod <pod> -o jsonpath='{.metadata.ownerReferences}' # Owner of this Pod
kubectl get namespace <namespace> -o jsonpath='{.status.conditions}' # Why the namespace deletion is stuck
kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -n <namespace> # What is left inside

Check yourself

  1. You delete a PVC and it stays Terminating for an hour. What is the most likely reason?
  2. You delete a Deployment with the default policy. Who removes its ReplicaSet and Pods?
  3. A backup operator was removed, then its namespace. The namespace is stuck in Terminating. What should you check first?

Further reading: Finalizers · Garbage collection · Owners and dependents