Skip to main content

CKAD Ep 5: Storage & Persistent Workloads

Rachmat Hidayat
Author
Rachmat Hidayat
Learn & sharing insights on TypeScript, Go, Kubernetes, DevOps, DevSecOps, SRE, Platform Engineering, AI/ML Engineering, and MLOps.
kubernetes-certification-path - This article is part of a series.
Part 205: This Article
Containers are ephemeral by default—when a container restarts, all data written to its local filesystem is lost. On the CKAD exam, you must demonstrate how to attach persistent storage to Pods using PVCs and StorageClasses.

TL;DR (Quick Summary)
#

  • PersistentVolume (PV): Physical storage resource provisioned in the cluster (cluster-scoped).
  • PersistentVolumeClaim (PVC): Request for storage by a user/developer (namespace-scoped).
  • Access Modes:
    • ReadWriteOnce (RWO): Mountable as read-write by a single node.
    • ReadOnlyMany (ROX): Mountable as read-only by many nodes.
    • ReadWriteMany (RWX): Mountable as read-write by many nodes (NFS, CephFS).
  • Reclaim Policies: Retain (manual cleanup), Delete (auto-destroys backing storage).

1. Storage Abstraction Layer
#

graph TD
    SC["StorageClass: fast-ssd
(provisioner: kubernetes.io/no-provisioner)"] -->|Provisions| PV["PersistentVolume: pv-data
(5Gi, hostPath: /data)"] PVC["PersistentVolumeClaim: pvc-app
(requests: 2Gi, accessModes: [ReadWriteOnce])"] -->|Binds to| PV Pod["Application Pod"] -->|volumeMounts: /usr/share/nginx/html| PVC

2. CKAD Terminal Hands-on Scenarios
#

Scenario A: Create PersistentVolume
#

Create a PersistentVolume named pv-analytics with 5Gi capacity, ReadWriteOnce access mode, Retain reclaim policy, using hostPath directory /mnt/data.

pv-analytics.yaml:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-analytics
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: /mnt/data

Apply and verify PV creation:

kubectl apply -f pv-analytics.yaml
kubectl get pv pv-analytics

Scenario B: Create PersistentVolumeClaim & Bind to Pod
#

Create a PVC named pvc-analytics requesting 2Gi storage with ReadWriteOnce access mode, then mount it into a Pod named data-writer at /var/data.

pvc-analytics.yaml:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-analytics
  namespace: default
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi

data-writer-pod.yaml:

apiVersion: v1
kind: Pod
metadata:
  name: data-writer
spec:
  volumes:
    - name: storage-vol
      persistentVolumeClaim:
        claimName: pvc-analytics
  containers:
    - name: writer
      image: busybox:1.36
      command: ["sh", "-c", "echo 'Hello persistent storage' > /var/data/out.txt && sleep 3600"]
      volumeMounts:
        - name: storage-vol
          mountPath: /var/data

Verify binding status:

kubectl apply -f pvc-analytics.yaml
kubectl apply -f data-writer-pod.yaml
kubectl get pvc pvc-analytics
# Status must show: Bound

3. Storage Troubleshooting Matrix for CKAD
#

Symptom / ErrorRoot CauseSolution
PVC is in Pending stateNo PV matches accessMode or capacityCreate matching PV or lower PVC storage request
PVC Pending (StorageClass mismatch)PVC specifies storageClassName different from PVMatch storageClassName exactly or set to ""
Pod ContainerCreatingPV hostPath directory missing on nodeEnsure directory exists on target node or use dynamic provisioner

Summary & Next Steps
#

In this episode, we covered:

  • Creating PersistentVolumes and requesting storage via PVCs.
  • Access modes (ReadWriteOnce, ReadWriteMany) and reclaim policies.
  • Mounting PVCs into Pod containers.
  • Debugging PVC Pending status issues.

In CKAD Episode 6: Health Probes & Pod Debugging, we will master Liveness/Readiness/Startup probes and troubleshooting crashing containers!

kubernetes-certification-path - This article is part of a series.
Part 205: This Article