Assignment 2: Run a stateful workload with a PVC
Goal: Run a workload that keeps its data by claiming persistent storage from the lab's NFS StorageClass, and prove the data survives the Pod being deleted and rescheduled.
Where: From the Jumpbox (kubectl/helm/k9s ready). Persistent storage comes from the NFS server at 10.100.100.12, exposed as a ReadWriteMany (RWX) StorageClass. Cluster workers are 10.100.100.8/.9/.10.
Tasks
- Work in your own namespace (reuse the one from Assignment 1, or
kubectl create namespace <yourname>). - Find the lab's NFS StorageClass name:
kubectl get storageclass. Note the exact name — you'll put it instorageClassName. - Write a PersistentVolumeClaim named
datawithaccessModes: [ReadWriteMany],storageClassName: <nfs-class>, andresources.requests.storage: 1Gi. Apply it and confirmkubectl get pvc -n <yourname>showsSTATUS: Bound. Note the PV it bound to withkubectl get pv. - Write a Deployment named
recorder(1 replica) runningbusybox:1.36that appends a timestamped line to a file on the mounted volume every few seconds, e.g. command:sh -c "while true; do echo \"$(date) from $(hostname)\" >> /data/log.txt; sleep 5; done". Mount thedataPVC at/data. - Apply it, wait until
Running, then read the file:kubectl exec deploy/recorder -n <yourname> -- cat /data/log.txt. Confirm lines are accumulating. - Prove persistence: delete the Pod (
kubectl delete pod <recorder-pod> -n <yourname>), let the Deployment recreate it, thencat /data/log.txtagain — the old lines must still be there, with new ones appended after the gap. - Prove RWX sharing: scale
recorderto 3 replicas. They may land on different workers. Exec into each and confirm they are all reading/writing the same/data/log.txt(you'll see lines from multiple hostnames). This only works because the StorageClass is ReadWriteMany. - Inspect the reclaim policy of your PV:
kubectl get pv <name> -o jsonpath='{.spec.persistentVolumeReclaimPolicy}'. Write one sentence in your README on what would happen to the data if you deleted the PVC.
Deliverable
YAML manifests (pvc.yaml, deployment.yaml) plus a README.md showing: the bound PVC/PV, the file contents before and after the Pod delete (to prove persistence), output from at least two replicas writing to the same file (to prove RWX), and your one-sentence note on the reclaim policy.
Acceptance criteria — you're done when:
-
kubectl get pvc data -n <yourname>showsBoundto a PV from the NFS StorageClass. - The PVC uses
accessModes: [ReadWriteMany]. - The
recorderPod mounts the PVC at/dataand is appending to/data/log.txt. - After deleting the Pod and letting it be recreated, the earlier log lines are still present (persistence proven).
- With 3 replicas, more than one Pod hostname appears in the same
/data/log.txt(RWX sharing proven). - Your README states the PV's reclaim policy and what happens to data on PVC deletion.
- Applying
kubectl apply -f .into a clean namespace reproduces the whole setup.
Hints
- PVC stuck in
Pending? Checkkubectl describe pvc data -n <yourname>for events — usually a wrong/missingstorageClassNameor an access mode the class doesn't support. - Re-read the Persistent Storage lesson, especially the PV/PVC/StorageClass flow diagram and the RWO-vs-RWX section.
- A single RWO claim would block multiple Pods on different nodes — that is exactly why this assignment requires RWX.
- Use
kubectl get pods -o wide -n <yourname>to confirm your replicas really landed on different workers (.8/.9/.10). - To exec into a specific replica:
kubectl get pods -n <yourname>, thenkubectl exec <pod> -n <yourname> -- cat /data/log.txt. - Blocked for >~30 min after re-reading the lessons? Bring what you've tried to your mentor.
No comments to display
No comments to display