liveBook · Manning

Reclaim policy

As explained in Kubernetes for Developers

A reclaim policy is a Kubernetes storage setting that determines what happens to underlying storage after its persistent volume is released.

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

How Kubernetes for Developers covers it

How deep it goes
Explains both policy choices and shows StorageClass configuration, PV inspection, and a disk-recovery procedure.
Examples
Uses StorageClass YAML, Redis disk recovery, and a scratch-volume Pod to contrast Retain with Delete.
What it assumes
Assumes familiarity with Pods and storage claims while introducing reclaim behavior through inspection commands and concrete workloads.
What you can do after
Operate/configure it by selecting a StorageClass policy, checking a PV, and preserving a disk for later recovery.
How it connects
Connects StorageClasses, PersistentVolumes, PersistentVolumeClaims, StatefulSets, and generic ephemeral volumes through their different deletion lifecycles.

Also explained in

Compare how 3 books explain reclaim policy →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes for Developers. The section links point to the parts of the book it draws on.