Persistent claims and retention
A disk request for each member
A PersistentVolumeClaim (PVC) is a request for storage. A PersistentVolume (PV) represents storage made available to a cluster. A binding connects the two; a storage driver or provisioner may allocate the backing storage. With a claim template, a StatefulSet associates a separate claim with each member. This is useful for data that must outlive a Pod object. It is not a mechanism for copying data between members.
Request one claim per ordinal
volumeClaimTemplates:- metadata: name: data spec: accessModes: - ReadWriteOnce storageClassName: ledger-study-storage resources: requests: storage: 1GipersistentVolumeClaimRetentionPolicy: whenDeleted: Retain whenScaled: RetainPartial StatefulSet spec, not a standalone resource. The three claims are data-ledger-0, data-ledger-1 and data-ledger-2. Each requests 1Gi: a total requested capacity of 3Gi, not a measured disk usage or cost. ReadWriteOnce means read-write mounting by one node, not necessarily one Pod. The fixture StorageClass is deliberately not provided. Without suitable storage the claims may remain pending and the workload may fail to start.
Two separate deletion decisions
The StatefulSet claim-retention policy decides whether template-created PVCs survive controller deletion (whenDeleted) and scale-down (whenScaled). Retain is the default for both; explicit Retain makes the intent visible. The field became stable in Kubernetes 1.32; verify the selected cluster and feature configuration. A normal Pod replacement is not a scale-down. Separately, a PV’s reclaim policy controls what happens to its storage after release. With Retain, manual reclamation is required. With Delete and a supporting driver, the underlying storage can be removed. Neither setting replaces backups.
Compare scale-down scenarios
Start with three bound claims and scale down to one in a hypothetical healthy cluster. With whenScaled: Retain, all three claims remain. With whenScaled: Delete, claims for ordinals 1 and 2 are targeted for deletion after their Pods terminate; actual deletion can be delayed. A PV with Retain can preserve the backing asset after the claim disappears, while Delete can remove it. whenDeleted controls a different event, so changing it does not by itself change the scale-down outcome.
Avoid accidental data loss
Inspect PVC names, PV bindings, reclaim policies and application backups before changes. A namespace deletion also removes its namespaced claims, so retaining claims at the StatefulSet level is not a namespace-wide protection. A surviving PVC does not guarantee healthy data, safe multi-node access or a successful restore. Do not force-delete Pods or remove finalizers to make a pending storage operation disappear.
Practice
Use retention.json to explain the three scale-down outcomes and what still requires driver evidence. Calculate requested storage for four members using the same template. Identify the risks of removing the namespace. No storage is provisioned in this exercise.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Persistent claims and retention — knowledge check
Apply the chapter concepts using synthetic offline scenarios.
Which object requests persistent storage?
Three templates each request 1Gi. What is the combined requested capacity?
What remains after a completed scale-down from three to one with whenScaled: Retain?
Which setting governs the PV after its claim is released?
What is a risk of deleting the lab namespace?