0
0
Kubernetesdevops~20 mins

Reclaim policies (Retain, Delete) in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding Kubernetes PersistentVolume Reclaim Policies
📖 Scenario: You are managing storage in a Kubernetes cluster. You want to understand how PersistentVolumes behave when their associated PersistentVolumeClaims are deleted. This depends on the reclaimPolicy set on the PersistentVolume.There are two main reclaim policies: Retain and Delete. Retain keeps the volume and data after the claim is deleted, while Delete removes the volume and data.
🎯 Goal: Create a Kubernetes PersistentVolume manifest with a reclaimPolicy set to Retain. Then create another PersistentVolume manifest with reclaimPolicy set to Delete. Finally, print the reclaim policies of both volumes to understand their behavior.
📋 What You'll Learn
Create a PersistentVolume named pv-retain with reclaimPolicy Retain
Create a PersistentVolume named pv-delete with reclaimPolicy Delete
Store the reclaim policies in variables named retain_policy and delete_policy
Print the values of retain_policy and delete_policy
💡 Why This Matters
🌍 Real World
Kubernetes administrators use reclaim policies to control what happens to storage volumes when applications stop using them. This helps prevent accidental data loss or frees up storage automatically.
💼 Career
Understanding reclaim policies is essential for DevOps engineers and cloud administrators managing persistent storage in Kubernetes clusters.
Progress0 / 4 steps
1
Create PersistentVolume with reclaimPolicy Retain
Create a dictionary called pv_retain representing a Kubernetes PersistentVolume manifest with these exact fields: metadata.name set to pv-retain, spec.capacity.storage set to 10Gi, spec.accessModes set to ["ReadWriteOnce"], spec.persistentVolumeReclaimPolicy set to Retain, and spec.hostPath.path set to /mnt/data-retain.
Kubernetes
Need a hint?

Use nested dictionaries to represent the manifest structure. The reclaim policy is under spec.persistentVolumeReclaimPolicy.

2
Create PersistentVolume with reclaimPolicy Delete
Create a dictionary called pv_delete representing a Kubernetes PersistentVolume manifest with these exact fields: metadata.name set to pv-delete, spec.capacity.storage set to 10Gi, spec.accessModes set to ["ReadWriteOnce"], spec.persistentVolumeReclaimPolicy set to Delete, and spec.hostPath.path set to /mnt/data-delete.
Kubernetes
Need a hint?

Follow the same structure as pv_retain, but change the name and reclaim policy accordingly.

3
Extract reclaim policies into variables
Create two variables: retain_policy and delete_policy. Assign retain_policy the value of pv_retain["spec"]["persistentVolumeReclaimPolicy"] and delete_policy the value of pv_delete["spec"]["persistentVolumeReclaimPolicy"].
Kubernetes
Need a hint?

Access nested dictionary keys step-by-step to get the reclaim policy values.

4
Print reclaim policies
Write two print statements to display the values of retain_policy and delete_policy exactly as: print("Retain policy:", retain_policy) and print("Delete policy:", delete_policy).
Kubernetes
Need a hint?

Use print with a string and the variable separated by a comma to display the policy names.