StatefulSet PVC Retention
A StatefulSet is scaled down or deleted, and its PVCs either stay behind with their data or get deleted soon after. Who decides that, what does a replica find when you scale back up, and does the disk go too?
Play the animation 5 steps, animated, plays on a computer or a tablet
StatefulSet PVC Retention, step by step
-
Each row flips one field of the policy on StatefulSet web while the other stays at the default, Retain. A field at Retain adds no ownerReference, so its event deletes no claim. When whenDeleted is Delete, the controller writes an ownerReference to web on the claims of every current Pod, existing or new.
Play from step 1 -
When web is scaled to two, the controller deletes the highest ordinal, Pod web-2. Retain leaves data-web-2 Bound with its data. Delete first makes Pod web-2 its owner, so once the Pod is gone the garbage collector deletes the claim, and its PV, set to Delete, takes the disk.
Play from step 2 -
When web is scaled back to three, the controller creates web-2 again. Under Retain the new Pod mounts the same data-web-2, data intact. Under Delete the controller waits out the old claim, creates a fresh one of that name before the Pod, and with WaitForFirstConsumer its empty volume comes after the Pod.
Play from step 3 -
When web is deleted with the default background cascade, its Pods go too. Under Retain all three claims stay Bound with no owner. Under Delete the garbage collector deletes the claims web owns along with its Pods, PVC protection holds each until its Pod is gone, and each PV set to Delete takes its disk.
Play from step 4 -
Delete removes claims, never disks directly. Had the PVs said Retain, the same garbage collection would delete the three claims and leave every volume Released with its data: the reclaimPolicy on each PV, not this policy, decides the disk.
Play from step 5