In this lesson, you will learn how to configure reclaimPolicy to decide whether your physical storage remains intact or gets wiped once a PersistentVolumeClaim (PVC) is deleted.
Understanding the Reclaim Policy
When you provision storage for a Kubernetes application, the PersistentVolume (PV) acts as the bridge between your cluster and the underlying physical storage asset. By default, when a developer deletes a PVC, the associated PV might still hang around, or it might be deleted entirely, depending on the reclaimPolicy defined in your StorageClass.
There are two primary policies you should know:
Retain: This is the "safety-first" mode. If you delete the PVC, the PV is not deleted. The status of the volume moves toReleased. Your data remains safe on the physical disk, but the volume is not immediately available for other claims because the data must be manually cleaned up or reclaimed by an administrator.Delete: This is the "automation-first" mode. If you delete the PVC, Kubernetes automatically deletes the underlying PV and triggers the removal of the asset from the storage provider (e.g., AWS EBS or GCP Persistent Disk). Use this when your storage lifecycle is tightly coupled to the application’s lifecycle.
Applying the Policy
You typically define this policy within your StorageClass resource so that all dynamically provisioned volumes inherit the desired behavior:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: fast-storage
provisioner: kubernetes.io/aws-ebs
reclaimPolicy: Retain
parameters:
type: gp2
In this example, setting the reclaimPolicy to Retain ensures that if a developer accidentally deletes a database PVC, the underlying disk—and the data inside it—won't disappear automatically. You would then need to manually delete the PV once you have backed up the data. Conversely, changing this to Delete would ensure your cloud provider bill doesn't grow with "orphaned" disks after pods are decommissioned.
Choosing the right policy is a balancing act between protecting against accidental data loss and preventing storage clutter in your cluster.
Key Takeaway: The reclaimPolicy determines if physical storage is preserved (Retain) or automatically purged (Delete) when a PersistentVolumeClaim is deleted.