0
0
KubernetesComparisonBeginner · 4 min read

Retain vs Delete vs Recycle Reclaim Policy in Kubernetes Explained

In Kubernetes, the Retain reclaim policy keeps the Persistent Volume (PV) after its claim is deleted, requiring manual cleanup. The Delete policy automatically deletes the PV and its storage when the claim is removed. The Recycle policy (now deprecated) used to clean the volume for reuse by deleting its contents.
⚖️

Quick Comparison

This table summarizes the key differences between the three reclaim policies in Kubernetes Persistent Volumes.

Reclaim PolicyAction on PV after PVC deletionStorage CleanupAutomation LevelUse Case
RetainPV remains but is released and not deletedNo automatic cleanup; manual intervention neededManualData preservation and manual recovery
DeletePV and underlying storage are deletedAutomatic cleanup of storageAutomaticTemporary storage or dynamic provisioning
Recycle (Deprecated)PV is scrubbed and made available againDeletes files inside volume but keeps PVSemi-automaticReuse of volumes with basic cleanup
⚖️

Key Differences

The Retain policy keeps the Persistent Volume (PV) intact even after the Persistent Volume Claim (PVC) is deleted. This means the data remains on the storage, but the PV is released and no longer bound to any claim. Manual cleanup or recovery is required to reuse or delete the volume, making it suitable when data must be preserved.

The Delete policy automatically deletes both the PV and its underlying storage resource when the PVC is deleted. This is common with dynamically provisioned volumes where storage lifecycle is tied to the claim, simplifying cleanup and resource management.

The Recycle policy was designed to delete the contents of the volume (like deleting files) and then make the PV available again for new claims. However, it is deprecated and not recommended for use because it only supports basic cleanup and lacks flexibility compared to other methods.

💻

Retain Reclaim Policy Example

yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-retain-example
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: "/mnt/data-retain"
Output
Creates a PersistentVolume named 'pv-retain-example' with Retain policy that keeps data after PVC deletion.
↔️

Delete Reclaim Policy Equivalent

yaml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-delete-example
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Delete
  hostPath:
    path: "/mnt/data-delete"
Output
Creates a PersistentVolume named 'pv-delete-example' with Delete policy that removes storage after PVC deletion.
🎯

When to Use Which

Choose Retain when you need to keep data safe after the claim is deleted, such as for backups or manual recovery.

Choose Delete for dynamic storage where you want automatic cleanup to save resources and avoid manual steps.

Avoid Recycle as it is deprecated and offers limited cleanup; prefer manual scripts or external tools for volume reuse.

Key Takeaways

Retain keeps the volume and data after claim deletion, requiring manual cleanup.
Delete removes both the volume and storage automatically when the claim is deleted.
Recycle is deprecated and only cleaned volume contents without deleting the volume.
Use Retain for data preservation, Delete for automatic resource cleanup.
Avoid Recycle; use modern alternatives for volume reuse and cleanup.