Reserving a PersistentVolume

A disk kept after its PVC was deleted still holds valuable data, and it has to go to one new claim before any other grabs it. How do you reserve a volume like that, and why is naming it in that claim not enough?

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

Reserving a PersistentVolume, Kubernetes diagram

Reserving a PersistentVolume, step by step

  1. PV pv-data is Released: its claimRef still names the deleted claim app/data, UID included, so no claim can bind it. An administrator patches the claimRef to name app/restore, with no UID. A claimRef without a UID is a reservation, so the PV controller writes Available, for that one claim, which does not even exist yet.

    Play from step 1
  2. PVC app/scratch arrives asking for 10Gi with an empty storageClassName, a fit for pv-data in every other way. The binder skips any volume whose claimRef names another claim, so pv-data is not even a candidate. The rival gets a FailedBinding event and stays Pending, while the reserved volume keeps waiting for app/restore.

    Play from step 2
  3. Now app/restore is created with volumeName: pv-data and storageClassName set to an empty string, because left unset it would get the default StorageClass where the cluster marks one. Claim and volume name each other, so the binder binds them: it writes the claim UID into the claimRef, and both turn Bound, the old data still on the disk.

    Play from step 3
  4. If instead the administrator had only cleared the claimRef, pv-data would be Available to any claim that fits it, and volumeName alone reserves nothing. A named volume with no claimRef is checked for class, size, access modes and volume mode, not for node affinity. A rival matched first still takes the volume, so app/scratch binds and app/restore gets FailedBinding.

    Play from step 4

Sources