Deleting a storage claim should not accidentally erase the only copy of important data. A reclaim policy controls what happens to the disk behind a PersistentVolume (PV) when its bound PersistentVolumeClaim (PVC) is deleted. Check the policy before relying on a disk for a stateful workload. section 9.1.3
Choose the policy by what the disk contains:
- Delete removes the bound PV and its backing disk when the PVC is deleted. It suits caches, temporary data, and development resources that should clean themselves up. section 9.1.3
- Retain preserves the backing disk so it can be linked to a new PV and PVC, even in another cluster. You must manually delete disks you no longer need. section 9.1.3
A StorageClass specifies the reclaim policy for dynamically provisioned storage. Run `kubectl get storageclass` and inspect `RECLAIMPOLICY`; a default class may use Delete. For important data, select a class configured with `reclaimPolicy: Retain`. After provisioning, use `kubectl get pv` to check the resulting volume; if necessary, `kubectl edit pv $PV_NAME` can change its `persistentVolumeReclaimPolicy`. section 9.1.3 section 9.3
Listing 9.4 Chapter09/9.1.3_StorageClass/storageclass.yaml
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
annotations:
storageclass.kubernetes.io/is-default-class: "true" #1
name: example-default-rwo
parameters:
type: pd-balanced #2
provisioner: pd.csi.storage.gke.io
reclaimPolicy: Retain #3
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
#1 Optional annotation to set as default
#2 Platform-specific value to set the storage type
#3 Configured to preserve the disk if the PV is deleted
This StorageClass manifest sets `reclaimPolicy: Retain`. Its provisioner and disk-type parameter are platform-specific; the reclaim-policy field is the setting to look for. section 9.1.3
Recovering a stateful workload
A Redis StatefulSet can keep data after its Kubernetes objects are removed if its disk was provisioned with Retain. Re-create a PV pointing to that disk, bind a new PVC, and restore the workload to read the saved values. Deleting the StatefulSet alone does not delete its PVCs; deleting those PVCs is the consequential step when the policy is Delete. section 9.3
For a generic ephemeral volume used as scratch space, prefer Delete. Deleting its Pod also deletes its PVC, allowing the disk to be cleaned up rather than retained unnecessarily. section 9.4


