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
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
| Policy | PV after the PVC is gone | Cloud disk and data | Next step |
|---|---|---|---|
Delete (default for dynamic provisioning) | Deleted | Deleted | Nothing to clean up, and nothing to recover |
Retain (default for hand-made PVs) | Released, keeps claimRef | Kept | Admin deletes and recreates the PV, or removes claimRef |
Recycle (deprecated) | Available after rm -rf of the volume | Data wiped | Use dynamic provisioning instead |
| Reclamation failed | Failed, or Released with warning events | Unknown, check the backend | Read kubectl describe pv, fix the storage side, delete the PV |
| Symptom | Cause | Fix |
|---|---|---|
PVC stuck Terminating | A 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 PV | Released PVs do not bind again | Reclaim the PV by hand, then pre-bind with claimRef and volumeName |
PVC with volumeName got an empty new disk | storageClassName was left out, so the default class applied | Set 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
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