Skip to main content
Kubernetes coreLesson 11 of 13

PersistentVolume Lifecycle and Reclaim Policy

Someone deletes the PVC of a database. Does the disk go with it? Follow one PersistentVolume through Available → Bound → Released → (Failed) and see what the reclaim policy decides.

PV phaseBound
Reclaim policyDelete
claimRefshop/data
Data on diskpresent
Kubernetes clusterAdminkubectlPod db-0mounts PVCPVC datans shopPVC data-newns shopStorageClassreclaimPolicyPV pv-dbpersistentVolumeBoundPV controllerbinds · reclaimsCloud diskvol-0abc · the dataMountsBoundBacked by
RequestResponse / reportWatchAppears in a later step

What you will learn

  • The four PV phases and what moves a PV between them
  • Where the reclaim policy comes from: StorageClass or the PV itself
  • Why pvc-protection holds a PVC while a Pod uses it
  • Delete versus Retain, and patching the policy in time
  • Making a Released PV usable, and binding a PV by hand

What happens when the PVC is deleted​

PolicyPV after the PVC is goneCloud disk and dataNext step
Delete (default for dynamic provisioning)DeletedDeletedNothing to clean up, and nothing to recover
Retain (default for hand-made PVs)Released, keeps claimRefKeptAdmin deletes and recreates the PV, or removes claimRef
Recycle (deprecated)Available after rm -rf of the volumeData wipedUse dynamic provisioning instead
Reclamation failedFailed, or Released with warning eventsUnknown, check the backendRead kubectl describe pv, fix the storage side, delete the PV
SymptomCauseFix
PVC stuck TerminatingA Pod still uses it (kubernetes.io/pvc-protection)Stop or delete the Pod; take a backup or patch the PV to Retain first if needed
New PVC Pending next to a Released PVReleased PVs do not bind againReclaim the PV by hand, then pre-bind with claimRef and volumeName
PVC with volumeName got an empty new diskstorageClassName was left out, so the default class appliedSet storageClassName: "" on both the PVC and the PV

Try it yourself​

kubectl get pv # STATUS, CLAIM, RECLAIM POLICY, STORAGECLASS
kubectl get storageclass -o custom-columns=NAME:.metadata.name,RECLAIM:.reclaimPolicy
kubectl get pvc data -n shop -o jsonpath='{.metadata.finalizers}{"\n"}' # ["kubernetes.io/pvc-protection"]

# Keep the disk even if the PVC is deleted
kubectl patch pv pv-db -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'

# After the PVC is deleted: Released, with the old claimRef
kubectl get pv pv-db -o jsonpath='{.status.phase} {.spec.claimRef.namespace}/{.spec.claimRef.name}{"\n"}'

# Shortcut to make it Available again (old data stays on the disk)
kubectl patch pv pv-db --type json -p '[{"op":"remove","path":"/spec/claimRef"}]'
kubectl describe pv pv-db # Events explain a Failed phase

Check yourself

  1. A PVC was dynamically provisioned from a StorageClass that does not set reclaimPolicy. Someone deletes the PVC after its Pod is gone. What happens to the data?
  2. You delete a PVC while its Pod is still running. Why does it stay Terminating, and why is that useful?
  3. A PV with Retain is Released. A new PVC asks for it with volumeName, but stays Pending. What is the reason?

Further reading: Persistent Volumes · Change the Reclaim Policy of a PersistentVolume · How Storage Gets Attached (PVC·PV) · When Volumes Attach, and Failures · Deletion Is More Complex Than You Think