Skip to content

🎓 LEVEL 39 DEBRIEF: PV Reclaim Policies

Congratulations! You've mastered reclaim policies - essential for preventing accidental data loss!


📊 What You Fixed

The Problem:

spec:
  persistentVolumeReclaimPolicy: Delete  # ❌ Dangerous!
Result: When PVC deleted → PV deleted → All data permanently lost!

The Solution:

spec:
  persistentVolumeReclaimPolicy: Retain  # ✅ Safe!
Result: When PVC deleted → PV marked "Released" → Data preserved


🔍 Understanding Reclaim Policies

The Three Policies

1. Delete (Automatic Cleanup)

persistentVolumeReclaimPolicy: Delete
When PVC deleted: - PV automatically deleted - Storage released back to pool - All data permanently lost

Use for: Development, test environments, ephemeral data

2. Retain (Manual Cleanup)

persistentVolumeReclaimPolicy: Retain
When PVC deleted: - PV status → "Released" - Data remains on disk - Manual cleanup required - Data preserved

Use for: Production, databases, critical data

3. Recycle (Deprecated)

persistentVolumeReclaimPolicy: Recycle
- Runs rm -rf on volume - No longer recommended - Use Delete or Retain instead


💥 Common Mistakes

Mistake 1: Delete for Production

# Production database
persistentVolumeReclaimPolicy: Delete  # ❌ Data loss risk!

Fix:

persistentVolumeReclaimPolicy: Retain  # ✅ Safe

Mistake 2: Not Testing Deletion

# Never tested what happens when PVC deleted
kubectl delete pvc my-data
# Oops! All data gone with Delete policy

Mistake 3: Forgetting Manual Cleanup

# Using Retain but never cleaning up Released PVs
# Eventually: Out of storage capacity

🛡️ Best Practices

  1. Use Retain for production:

    persistentVolumeReclaimPolicy: Retain
    

  2. Document policy in annotations:

    metadata:
      annotations:
        policy-reason: "Production database - Retain required"
    

  3. Set in StorageClass:

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    reclaimPolicy: Retain  # Default for all PVs
    

  4. Process for Retain cleanup:

    # 1. Verify data no longer needed
    # 2. Backup if uncertain
    # 3. Delete PV manually
    kubectl delete pv my-pv
    # 4. Clean up underlying storage
    

  5. Monitor Released PVs:

    kubectl get pv | grep Released
    # Alert if too many accumulate
    


🎯 Key Takeaways

  1. Retain = Safe - Data preserved when PVC deleted
  2. Delete = Automatic - Data lost when PVC deleted
  3. Use Retain for production - Prevent accidental data loss
  4. Manual cleanup required - With Retain policy
  5. Set in StorageClass - For consistency

Well done! You understand reclaim policies! 🎉