Skip to content

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

  1. Apply pv.yaml - creates a PersistentVolume with a pre-populated data file.
  2. Apply pvc.yaml - creates a PersistentVolumeClaim that binds to the PV.
  3. Apply archive-pod.yaml - mounts the PVC.
  4. Exec into the pod and read /archive/password.txt.
  5. 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 1

kubectl apply -f pv.yaml
kubectl apply -f pvc.yaml
kubectl apply -f archive-pod.yaml

Hint 2

Check PVC is bound:

kubectl get pvc

Hint 3

The password is pvclaim3.


🔓 Unlock Room 25

openssl enc -aes-256-cbc -d -a -pbkdf2 \
        -in ../room_25/README             \
        -out ../room_25/README.txt        \
        -pass pass:PASSWORD
cat ../room_25/README.txt