PVC Protection Finalizers

A PVC has been deleted, yet it hangs in Terminating with no sign of going away, while the app that still uses it goes on writing to its disk. What is holding it, and what has to leave before the delete can finish?

Play the animation 7 steps, animated, plays on a computer or a tablet

PVC Protection Finalizers diagram: Why a deleted PersistentVolumeClaim sits in Terminating

PVC Protection Finalizers, step by step

  1. The claim is a handle, and the volume behind it is what stores the bytes. Kubelet resolved data-claim to data-vol and mounted it at /data, so the app writes through the claim into the disk. The finalizer guards the claim for as long as this Pod object exists.

    Play from step 1
  2. You run kubectl delete pvc data-claim. The API accepts it and writes a deletionTimestamp onto the object. With finalizers present, that is all a delete does. It is a request, recorded on the object, and nothing has been removed yet. Your terminal prints deleted anyway and then hangs, because kubectl waits for finalizers by default.

    Play from step 2
  3. The delete stops there. The finalizers list still holds kubernetes.io/pvc-protection, so the API server does not complete it and the object stays where it was, shown as Terminating. The Pod has noticed nothing: the volume is still mounted and the app is still writing to it, straight through a claim you already deleted.

    Play from step 3
  4. The protection is deliberate. Taking the claim away under a running Pod would pull the mount out from beneath it and could lose writes that are still in flight. Deletion also closes the claim to new users: a new Pod that names it is left unschedulable and stays Pending, without ever holding the claim.

    Play from step 4
  5. So the reason has to go. The Pod is deleted, or it finishes and its Pod object is removed, and as it goes Kubelet unmounts the volume and the claim loses its last consumer, the event the protection controller has been waiting for.

    Play from step 5
  6. The pvc-protection controller checks whether any Pod still uses the claim, finds none, and removes the finalizer from the object, which it could not do while web-0 existed. The finalizers list is now empty, and that was the last thing holding the outstanding delete, so the kubectl command hanging since step 2 is about to return.

    Play from step 6
  7. The moment the finalizers list is empty, the API server completes the delete it accepted five steps ago and the record leaves ETCD. The disk itself is a separate question, settled by the reclaim policy on the volume. So for a stuck Terminating claim, the thing to look for is the Pod object that still names it, finished or not: kubectl describe pvc lists it under Used By.

    Play from step 7

Sources