Module 7 ยท Lesson 7.2
StorageClasses & Dynamic Provisioning
You saw a StorageClass named in a PVC last lesson without really defining it. Here's what it actually is: a named template that tells the cluster how to dynamically provision storage when a PVC asks for it.
What's actually in a StorageClass
provisioner: rancher.io/local-path # which plugin creates the volume
reclaimPolicy: Delete # what happens to the PV when its PVC is deleted
volumeBindingMode: WaitForFirstConsumer
provisioneris the plugin doing the real work โ on EKS this would beebs.csi.aws.comorefs.csi.aws.com; on kind it's a simple local-path provisioner writing to each node's filesystem.reclaimPolicydecides whether the underlying storage is deleted or kept around after its PVC is deleted.Retainis what you'd want for anything you can't afford to lose to a typo.volumeBindingMode: WaitForFirstConsumerdelays actually creating the volume until a Pod using the PVC is scheduled โ critical in clouds where storage is zone-locked, so the volume gets created in the same zone as the Pod, not a random one.Immediateprovisions right away, which only really makes sense for storage with no such topology constraint.
A cluster can have many StorageClasses
Nothing stops you from having fast-ssd, cheap-hdd, and encrypted all
pointing at the same or different provisioners with different parameters
โ PVCs pick one by name via storageClassName. Exactly one can be marked
the cluster's default (an annotation on the StorageClass itself), used
when a PVC doesn't specify one at all.
The other common failure mode
Last lesson's bug was a request the provisioner genuinely couldn't satisfy.
This lesson's is simpler and, in practice, far more common: a typo in the
StorageClass name. There's no autocomplete enforcing that
storageClassName: fast-locall matches a real class โ it just won't, and
the PVC sits Pending with an unambiguous "not found" event, which is
almost a relief compared to the previous lesson's failure mode.
The infrastructure analogy
A StorageClass is closest to an EBS volume type + parameters template
(gp3, 3000 IOPS, encrypted) that you'd reference by name in a launch
template โ defined once, requested by name repeatedly, with the actual
provisioning handled by the cloud underneath.
In the lab, you'll define your own StorageClass and fix exactly this kind of name mismatch.
๐งช Lab: lab-14-storageclasses
Preview onlyGoal
See a StorageClass as what it really is โ a named template dynamic provisioning reads from โ and fix a one-character typo that's extremely common in real manifests.
Tasks
- Apply the starting manifests:
kubectl apply -f manifests/ - List StorageClasses:
kubectl get storageclassโ you now have two:standard(kind's built-in default) andfast-local(yours, same provisioner,reclaimPolicy: Retaininstead ofDelete). - Check status:
kubectl get pvc,pod -n lab-14-storageclassesโapp-datais stuckPending. - Diagnose:
kubectl describe pvc app-data -n lab-14-storageclassesโ read the Events. - Compare the StorageClass name the PVC asks for against
kubectl get storageclassโ find the typo. - Fix it in
manifests/pvc-and-pod.yaml, thenkubectl delete -f manifests/pvc-and-pod.yaml && kubectl apply -f manifests/pvc-and-pod.yaml - Confirm:
kubectl get pvc app-data -n lab-14-storageclassesshowsBoundwithSTORAGECLASS=fast-local.
Check
Run the check once app-data is Bound to the fast-local class and
app is Running.
This lab runs against a real local Kubernetes cluster with an automated grader โ clone the repo and run make start to do it for real.
๐ Quiz
1. What does a StorageClass's `provisioner` field actually control?
2. Why does `volumeBindingMode: WaitForFirstConsumer` matter more on a real cloud than it does on kind?scenario
3. A PVC's `storageClassName` has a typo and matches no real StorageClass. What's the failure mode?
4. What does `reclaimPolicy: Retain` protect you from, compared to `Delete`?
5. Which of these can differ between two StorageClasses pointing at the same provisioner? (select all that apply)
Progress isn't saved in this preview โ run the course locally to track completion and grade labs for real.