CKA: Storage
10% of the CKA exam, 3 competencies. Back to the CKA overview.
Each competency lists what to know and the official documentation to read, then a demo you can run. Demos run on the demo lab, a throwaway kind cluster on your own machine; set it up once before you start.
Implement storage classes and dynamic volume provisioning
Section titled “Implement storage classes and dynamic volume provisioning”Know
- A StorageClass names a provisioner (CSI driver), parameters,
reclaimPolicy, andvolumeBindingMode. A PVC that names it gets a PV created on demand. WaitForFirstConsumerdelays provisioning until a pod is scheduled, so zonal disks land in the right zone.
Read
Demo: Write your own StorageClass
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace cka-sckubectl config set-context --current --namespace=cka-sc -
Read the default class, then create one that keeps the data after the claim is deleted.
Terminal window kubectl get storageclass standard -o yaml | grep -E 'provisioner|reclaimPolicy|volumeBindingMode|is-default'kubectl apply -f - <<'EOF'apiVersion: storage.k8s.io/v1kind: StorageClassmetadata:name: keepprovisioner: rancher.io/local-pathreclaimPolicy: RetainvolumeBindingMode: WaitForFirstConsumerEOF -
Claim from it and start a pod so the volume is provisioned.
Terminal window kubectl apply -f - <<'EOF'apiVersion: v1kind: PersistentVolumeClaimmetadata:name: keptspec:storageClassName: keepaccessModes: ["ReadWriteOnce"]resources:requests:storage: 1Gi---apiVersion: v1kind: Podmetadata:name: userspec:containers:- name: appimage: registry.k8s.io/e2e-test-images/busybox:1.37.0-2command: ["sleep", "3600"]volumeMounts:- name: vmountPath: /datavolumes:- name: vpersistentVolumeClaim:claimName: keptEOFkubectl wait --for=condition=Ready pod/user --timeout=120skubectl get pvc keptkubectl get pv -
Delete the pod and claim, then look at the volume.
Terminal window kubectl delete pod user && kubectl delete pvc keptkubectl get pv
What you should see: The PV was created for you by the provisioner and bound to the claim. After deleting the claim it stays, with status Released, because the class says Retain. With the default Delete it would be gone.
Clean up:
kubectl delete pv $(kubectl get pv -o jsonpath='{.items[?(@.spec.storageClassName=="keep")].metadata.name}')kubectl delete storageclass keepkubectl config set-context --current --namespace=defaultkubectl delete namespace cka-scPractise
- Mark a StorageClass as default with the
storageclass.kubernetes.io/is-default-classannotation and create a PVC withoutstorageClassName.
On this site
Configure volume types, access modes and reclaim policies
Section titled “Configure volume types, access modes and reclaim policies”Know
- Access modes: ReadWriteOnce (one node), ReadOnlyMany, ReadWriteMany, ReadWriteOncePod (one pod).
- Reclaim policies: Delete removes the backing storage with the PV, Retain keeps it for manual recovery.
Read
Demo: Three volume types in one pod
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace cka-voltypeskubectl config set-context --current --namespace=cka-voltypes -
Mount an emptyDir, a ConfigMap, and a projected service account token in one pod.
Terminal window kubectl create configmap settings --from-literal=greeting=hellokubectl apply -f - <<'EOF'apiVersion: v1kind: Podmetadata:name: volumesspec:containers:- name: appimage: registry.k8s.io/e2e-test-images/busybox:1.37.0-2command: ["sh", "-c", "echo scratch > /scratch/f; ls /scratch /config /token; cat /config/greeting; sleep 3600"]volumeMounts:- {name: scratch, mountPath: /scratch}- {name: config, mountPath: /config, readOnly: true}- {name: token, mountPath: /token, readOnly: true}volumes:- name: scratchemptyDir:sizeLimit: 64Mi- name: configconfigMap:name: settings- name: tokenprojected:sources:- serviceAccountToken:path: tokenexpirationSeconds: 3600audience: demoEOFkubectl wait --for=condition=Ready pod/volumes --timeout=120s && kubectl logs volumes -
Ask for an access mode the provisioner can’t give.
Terminal window kubectl apply -f - <<'EOF'apiVersion: v1kind: PersistentVolumeClaimmetadata:name: sharedspec:accessModes: ["ReadWriteMany"]resources:requests:storage: 1GiEOFkubectl run mounter --image=registry.k8s.io/e2e-test-images/busybox:1.37.0-2 --overrides='{"spec":{"containers":[{"name":"m","image":"registry.k8s.io/e2e-test-images/busybox:1.37.0-2","command":["sleep","3600"],"volumeMounts":[{"name":"v","mountPath":"/v"}]}],"volumes":[{"name":"v","persistentVolumeClaim":{"claimName":"shared"}}]}}'sleep 20; kubectl describe pvc shared | sed -n '/Events:/,$p'
What you should see: The first pod lists all three mounts and prints hello. The RWX claim never binds: the local-path provisioner only supports ReadWriteOnce (and ReadWriteOncePod), and the claim’s events say so. Access modes are a promise the storage backend must be able to keep.
Clean up:
kubectl config set-context --current --namespace=defaultkubectl delete namespace cka-voltypesPractise
- Create a hostPath PV and a PVC that binds to it by size and access mode.
On this site
Manage persistent volumes and persistent volume claims
Section titled “Manage persistent volumes and persistent volume claims”Know
- PV and PVC bind one-to-one. Expanding a PVC requires
allowVolumeExpansion: trueon its StorageClass. - A PVC in use is protected from deletion by a finalizer until no pod uses it.
Read
Demo: Bind a claim to a volume you created by hand
-
Create a namespace for this demo and make it the default for your context.
Terminal window kubectl create namespace cka-pvkubectl config set-context --current --namespace=cka-pv -
Create a static PV on one node with a hostPath, and a claim that selects it.
Terminal window kubectl apply -f - <<'EOF'apiVersion: v1kind: PersistentVolumemetadata:name: manual-pvlabels:tier: manualspec:capacity:storage: 1GiaccessModes: ["ReadWriteOnce"]persistentVolumeReclaimPolicy: RetainstorageClassName: ""hostPath:path: /tmp/manual-pvtype: DirectoryOrCreatenodeAffinity:required:nodeSelectorTerms:- matchExpressions:- key: kubernetes.io/hostnameoperator: Invalues: ["kind-worker"]---apiVersion: v1kind: PersistentVolumeClaimmetadata:name: manual-claimspec:storageClassName: ""selector:matchLabels:tier: manualaccessModes: ["ReadWriteOnce"]resources:requests:storage: 500MiEOFkubectl get pv manual-pv; kubectl get pvc manual-claim -
Try to expand a dynamically provisioned claim. Bind it first: only bound claims can grow.
Terminal window kubectl get storageclass standard -o jsonpath='{.allowVolumeExpansion}{"\n"}'kubectl apply -f - <<'EOF'apiVersion: v1kind: PersistentVolumeClaimmetadata:name: growspec:accessModes: ["ReadWriteOnce"]resources:requests:storage: 1Gi---apiVersion: v1kind: Podmetadata:name: growerspec:containers:- name: appimage: registry.k8s.io/e2e-test-images/busybox:1.37.0-2command: ["sleep", "3600"]volumeMounts:- {name: v, mountPath: /data}volumes:- name: vpersistentVolumeClaim:claimName: growEOFkubectl wait --for=condition=Ready pod/grower --timeout=120skubectl patch pvc grow -p '{"spec":{"resources":{"requests":{"storage":"2Gi"}}}}'
What you should see: The manual claim binds to manual-pv even though it asked for less: a claim gets a whole volume. The expansion patch is rejected because the standard class doesn’t set allowVolumeExpansion: true; on a CSI driver that supports it, the same patch grows the volume.
Clean up:
kubectl delete pv manual-pvkubectl config set-context --current --namespace=defaultkubectl delete namespace cka-pvPractise
- Bind a PVC, mount it in a pod, write a file, delete and recreate the pod, and read the file back.
On this site
Domain and competency names are from the CNCF CKA curriculum (v1.37), cncf/curriculum, licensed CC BY 4.0. Summaries, demos, and exercises are original to this site.