Room 24
PERSISTENTVOLUMES
The Eternal Archive
- PersistentVolumes (PV) and PersistentVolumeClaims (PVC) decouple storage from pods.
- Storage persists beyond pod lifecycle. Claim a volume and read the archived password.
📜 Mission Briefing
- Apply
pv.yaml- creates a PersistentVolume with a pre-populated data file. - Apply
pvc.yaml- creates a PersistentVolumeClaim that binds to the PV. - Apply
archive-pod.yaml- mounts the PVC. - Exec into the pod and read
/archive/password.txt. - The password is
pvclaim3.
Key Commands
| Command | Purpose |
|---|---|
kubectl get pv |
List PersistentVolumes |
kubectl get pvc |
List PVCs |
kubectl describe pv NAME |
PV details |
kubectl describe pvc NAME |
PVC details and binding |
How PV/PVC Work
# PersistentVolume: Cluster-wide storage resource
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-pv
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce # RWO, ROX, RWX
persistentVolumeReclaimPolicy: Retain # Retain, Delete, Recycle
storageClassName: manual
hostPath:
path: /mnt/data
---
# PersistentVolumeClaim: Request for storage
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
storageClassName: manual
---
# Pod using the PVC
apiVersion: v1
kind: Pod
metadata:
name: storage-pod
spec:
containers:
- name: app
image: busybox
command: ['sh', '-c', 'cat /data/password.txt && sleep 3600']
volumeMounts:
- name: storage
mountPath: /data
volumes:
- name: storage
persistentVolumeClaim:
claimName: my-pvc
# Access Modes:
# ReadWriteOnce (RWO): One node read-write
# ReadOnlyMany (ROX): Many nodes read-only
# ReadWriteMany (RWX): Many nodes read-write
# Reclaim Policies:
# Retain: Keep data after PVC deletion (manual cleanup)
# Delete: Delete storage when PVC is deleted
# Recycle: Basic scrub (deprecated, use dynamic provisioning)
# PV lifecycle: Available → Bound → Released
kubectl get pv
kubectl get pvc
# PV binding: PVC matches PV by storageClassName, accessModes, and capacity
Hints
Hint 3
The password is pvclaim3.