Tasks
-
Create a namespace named
storage-labSolution
PVC and workload resources live in this namespace. The PV itself is cluster-scoped.
kubectl create namespace storage-lab -
Create a PersistentVolume named
○data-pvwith hostPath/mnt/data, capacity1Gi, accessModeReadWriteOnce, storageClassNamemanual, reclaimPolicyRetainSolution
No imperative command exists for PersistentVolume. In the exam, open the docs at Concepts > Storage > Persistent Volumes and copy the hostPath example. PV is cluster-scoped, no
-nflag needed.apiVersion: v1 kind: PersistentVolume metadata: name: data-pv spec: capacity: storage: 1Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Retain storageClassName: manual hostPath: path: /mnt/datakubectl apply -f pv.yaml -
Create a PersistentVolumeClaim named
○data-pvcin namespacestorage-labwith storageClassNamemanual, accessModeReadWriteOnce, and requested storage500MiSolution
No imperative command exists for PersistentVolumeClaim. In the exam, open the docs at Concepts > Storage > Persistent Volumes > PersistentVolumeClaims. Save the exemple in a file with nano and update it before applying it.
storageClassNameandaccessModesmust match the PV exactly for binding to succeed.apiVersion: v1 kind: PersistentVolumeClaim metadata: name: data-pvc namespace: storage-lab spec: storageClassName: manual accessModes: - ReadWriteOnce resources: requests: storage: 500Mikubectl apply -f pvc.yaml -
Create pod
○storage-podin namespacestorage-lab, imagebusybox:1.36, commandsleep 3600, with a volume from PVCdata-pvcmounted at/dataSolution
Generate a base manifest quickly with kubectl: Then adapt it so
pod.yamlmatches this final manifest: Thenamevalue must be identical involumesandvolumeMounts.kubectl run storage-pod -n storage-lab --image=busybox:1.36 --dry-run=client -o yaml -- sleep 3600 > pod.yamlapiVersion: v1 kind: Pod metadata: name: storage-pod namespace: storage-lab spec: containers: - name: storage-pod image: busybox:1.36 command: ["sleep", "3600"] volumeMounts: - name: data mountPath: /data volumes: - name: data persistentVolumeClaim: claimName: data-pvckubectl apply -f pod.yaml kubectl wait --for=condition=Ready pod/storage-pod -n storage-lab --timeout=60s -
Write a file inside
storage-podto confirm the volume is writable, then read it backSolution
If the mount is correct, write and read both succeed.
kubectl exec -n storage-lab storage-pod -- sh -c 'echo cka-ok > /data/probe.txt && cat /data/probe.txt'