What if your storage cleaned itself up perfectly every time you delete an app?
Why Reclaim policies (Retain, Delete) in Kubernetes? - Purpose & Use Cases
Imagine you manage storage for many apps on Kubernetes. When an app is deleted, you must manually clean up its storage to avoid wasting space or losing important data.
Manually tracking and deleting storage is slow and risky. You might delete data needed later or leave unused storage consuming resources, causing confusion and extra work.
Reclaim policies automate what happens to storage when apps are removed. You choose to keep data (Retain) or delete it automatically (Delete), saving time and avoiding mistakes.
kubectl delete pod myapp
# Then manually delete storage volumeSet reclaimPolicy: Delete on PersistentVolume
# Storage cleans up automatically when PVC is deletedIt enables safe, automatic management of storage lifecycle tied to app usage, freeing you from manual cleanup tasks.
A developer deletes a test app and its storage is deleted automatically, saving cluster space without extra steps.
Manual storage cleanup is slow and error-prone.
Reclaim policies automate storage retention or deletion.
This saves time and prevents data loss or wasted resources.
Practice
Retain reclaim policy do in Kubernetes Persistent Volumes?Solution
Step 1: Understand reclaim policies
Reclaim policies define what happens to storage after the claim is deleted.Step 2: Identify Retain behavior
The Retain policy keeps the volume and data intact for manual intervention.Final Answer:
Keeps the volume and data after the PersistentVolumeClaim is deleted for manual cleanup. -> Option AQuick Check:
Retain = Keep data safe [OK]
- Confusing Retain with automatic deletion
- Thinking Retain backs up data automatically
- Assuming Retain prevents claim deletion
Delete?Solution
Step 1: Check correct YAML key and value
The key ispersistentVolumeReclaimPolicy, and value is case-sensitive.Step 2: Identify correct value for Delete
The value must be exactlyDeletewith capital D.Final Answer:
persistentVolumeReclaimPolicy: Delete -> Option BQuick Check:
Correct key and capitalized value = A [OK]
- Using lowercase 'delete' instead of 'Delete'
- Using underscore instead of camelCase key
- Mixing Retain and Delete values
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-example
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
hostPath:
path: /data/pv-example
What happens to the volume when the PersistentVolumeClaim using this PV is deleted?
Solution
Step 1: Identify reclaim policy in YAML
The reclaim policy is set asRetaininpersistentVolumeReclaimPolicy.Step 2: Understand Retain effect on deletion
Retain means the volume and data stay after claim deletion for manual handling.Final Answer:
The volume is retained and data remains for manual cleanup. -> Option CQuick Check:
Retain policy = keep volume and data [OK]
- Assuming data deletes automatically with Retain
- Confusing persistentVolumeReclaimPolicy with reclaimPolicy key
- Thinking volume is backed up automatically
Delete but after deleting the PersistentVolumeClaim, the volume still exists. What is the most likely cause?Solution
Step 1: Understand Delete reclaim policy
Delete policy should remove the volume automatically after claim deletion.Step 2: Check storage class support
If the storage class does not support dynamic deletion, volume remains despite policy.Final Answer:
The storage class does not support automatic deletion. -> Option DQuick Check:
Storage class support needed for Delete policy [OK]
- Assuming reclaim policy misspelling always causes failure
- Ignoring storage class role in deletion
- Not verifying claim deletion status
Solution
Step 1: Choose policy to keep data after claim deletion
Retain policy keeps the volume and data safe after claim deletion.Step 2: Automate cleanup after backup
Since Retain does not delete automatically, a cleanup job is needed to remove volumes later.Final Answer:
Use Retain policy and configure a cleanup job to delete volumes later. -> Option AQuick Check:
Retain + cleanup job = safe backup + automation [OK]
- Assuming Delete keeps data for backup
- Expecting Retain to delete volumes automatically
- Not planning manual or automated cleanup after Retain
Ready to prove it?
Pass the test and this pattern moves unknown
