Room 25
STORAGECLASSES
The Provisioner’s Workshop
- StorageClasses enable dynamic provisioning - claim storage and it’s created automatically.
- No need to pre-create PVs. The StorageClass handles it.
📜 Mission Briefing
- List existing StorageClasses:
kubectl get sc. - Examine the default StorageClass in your Kind cluster.
- Create a PVC that uses the default StorageClass - storage is provisioned dynamically.
- Apply
dynamic-pvc.yamlanddynamic-pod.yaml. - Write a file in the dynamically provisioned volume, then read it back.
- The password is stored in the StorageClass annotation:
storclass.
Key Commands
| Command | Purpose |
|---|---|
kubectl get sc |
List StorageClasses |
kubectl describe sc NAME |
StorageClass details |
kubectl get pvc |
See bound PVCs |
kubectl get pv |
See dynamically created PVs |
How StorageClasses Work
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: fast-storage
annotations:
storageclass.kubernetes.io/is-default-class: "true"
provisioner: rancher.io/local-path # Kind uses local-path-provisioner
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
# PVC with StorageClass (dynamic provisioning)
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: dynamic-claim
spec:
accessModes:
- ReadWriteOnce
storageClassName: standard # Name of StorageClass
resources:
requests:
storage: 1Gi
# PV is automatically created when PVC is created!
# Common provisioners:
# kubernetes.io/aws-ebs → AWS EBS volumes
# kubernetes.io/gce-pd → Google Persistent Disk
# kubernetes.io/azure-disk → Azure Managed Disk
# rancher.io/local-path → Kind local storage
# kubernetes.io/no-provisioner → Manual (no dynamic)
# Dynamic provisioning flow:
# 1. Create StorageClass with provisioner
# 2. Create PVC referencing the StorageClass
# 3. Provisioner automatically creates a PV
# 4. PVC binds to the new PV
# 5. Pod mounts the PVC
# Set default StorageClass
kubectl patch storageclass standard \
-p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
Hints
Hint 2
Apply and check:
Hint 3
The password is storclass.