✦ For everyone, free.

Practical knowledge for real and everyday life

Home

Kubernetes StatefulSet Claim Retention Management

Kubernetes StatefulSet Claim Retention Management ensures persistent storage for stateful applications by retaining PVCs across pod restarts and rescheduling.

Kubernetes StatefulSet Claim Retention Management is the governance process surrounding decisions to actually delete a StatefulSet's persistent claims, covering how retention policy changes apply only prospectively rather than retroactively, and the deliberate decommissioning checklist required before permanently discarding stateful data, distinct from the mechanical retention policy fields themselves.


Policy Changes Are Not Retroactive

Existing Claims Keep Their Original Behavior

Changing persistentVolumeClaimRetentionPolicy on an existing StatefulSet affects only future deletion or scaling events; it does not retroactively alter what happens to claims that were already created, nor does it un-delete anything already removed under a prior policy setting.

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: claim-retention-management-example
spec:
  persistentVolumeClaimRetentionPolicy:
    whenScaled: Delete

Verifying the Policy Actually Took Effect

Because this field was introduced in a later Kubernetes version, retention management practice includes confirming the running cluster's version supports it and that the policy change was actually accepted by the API server, rather than assuming a policy edit silently succeeded.

kubectl get statefulset claim-retention-management-example -o jsonpath='{.spec.persistentVolumeClaimRetentionPolicy}'

The Decommissioning Checklist

Confirming No Active Dependency Before Deletion

Before deleting a claim believed to be no longer needed, retention management practice confirms the data is not still required by any downstream consumer, a replication target still reading from it, a backup process still referencing the associated volume snapshot, since PersistentVolumeClaim deletion is not easily reversible once the underlying volume is reclaimed.

kubectl get pvc data-claim-retention-management-example-4 -o jsonpath='{.status.phase}'

Taking a Final Snapshot Before Deletion

For any claim holding data with lasting value, retention management practice takes an explicit volume snapshot immediately before deletion, providing a recovery path independent of the claim's own lifecycle even after it is gone.

apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
  name: final-snapshot-ordinal-4
spec:
  volumeSnapshotClassName: csi-snapshotter
  source:
    persistentVolumeClaimName: data-claim-retention-management-example-4

Recording the Deletion Decision

Retention management practice logs the decision to delete a specific claim, who authorized it, why, and when, external to Kubernetes itself, since the object's own audit trail may be insufficient once the claim and its history are both gone.


Retention Policy Interaction With Namespace Deletion

Claims Are Namespace-Scoped

Deleting an entire namespace cascades to delete every PersistentVolumeClaim within it regardless of any StatefulSet-level retention policy, since namespace deletion operates at a different, more encompassing level of garbage collection; retention management practice treats namespace deletion as categorically more dangerous than StatefulSet deletion for exactly this reason.

kubectl delete namespace claim-retention-management-namespace

Auditing Orphaned Claims Periodically

Finding Claims With No Corresponding StatefulSet

Periodic audits for claims whose naming pattern implies StatefulSet ownership but whose corresponding StatefulSet no longer exists surface storage that may be safe to reclaim, or may represent data someone intentionally preserved after a StatefulSet's removal, requiring case-by-case judgment rather than blanket cleanup.

kubectl get pvc -o json | jq -r '.items[] | select(.metadata.name | test("^data-")) | .metadata.name'

Claim Retention Governance Diagram

Confirm no active dependency Take final snapshot Record decision Delete

Treating claim deletion as the deliberate, checklist-driven final step it should be, rather than a routine side effect of a scaling or cleanup command, is what protects against the specific class of stateful workload incidents caused by data loss that no rollback can undo.