Skip to content

Room 23

VOLUMES & MOUNTS


The Data Chamber

  • Containers are ephemeral - when they restart, their filesystem is lost.
  • Volumes persist data beyond container restarts. Mount volumes to save and share data.

📜 Mission Briefing

  1. Apply shared-volume.yaml - a pod with two containers sharing an emptyDir volume.
  2. Container writer writes a message to /data/message.txt every 5 seconds.
  3. Container reader reads from the same path.
  4. Exec into the reader container and read /data/message.txt.
  5. The last line contains the password: volumed7.

Key Commands
Command Purpose
kubectl exec POD -c CONTAINER -- cat /path Read from volume
kubectl describe pod NAME See volume mounts

Volume Types
# emptyDir: Temporary storage, shared between containers in a pod
# Deleted when pod is removed
apiVersion: v1
kind: Pod
metadata:
  name: shared-vol
spec:
  containers:
    - name: writer
      image: busybox
      command: ['sh', '-c', 'while true; do echo "volumed7" >> /data/message.txt; sleep 5; done']
      volumeMounts:
        - name: shared
          mountPath: /data
    - name: reader
      image: busybox
      command: ['sh', '-c', 'tail -f /data/message.txt']
      volumeMounts:
        - name: shared
          mountPath: /data
  volumes:
    - name: shared
      emptyDir: {}          # Can also set sizeLimit and medium
# hostPath: Mounts a directory from the host node's filesystem
# Use with caution - breaks portability
apiVersion: v1
kind: Pod
metadata:
  name: hostpath-pod
spec:
  containers:
    - name: app
      image: busybox
      volumeMounts:
        - name: host-data
          mountPath: /host-data
  volumes:
    - name: host-data
      hostPath:
        path: /tmp/data
        type: DirectoryOrCreate   # Directory, File, etc.
# Volume types:
# emptyDir:    Temp dir, pod lifetime
# hostPath:    Node filesystem mount
# configMap:   Mount ConfigMap as files
# secret:      Mount Secret as files
# persistentVolumeClaim: Persistent storage
# nfs:         Network File System
# downwardAPI: Pod metadata as files
# projected:   Combine multiple sources into one mount

Hints

Hint 1

kubectl apply -f shared-volume.yaml
kubectl exec shared-vol -c reader -- cat /data/message.txt

Hint 2

The writer container writes the password to the shared emptyDir volume.

Hint 3

The password is volumed7.


🔓 Unlock Room 24

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