Skip to content

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

  1. List existing StorageClasses: kubectl get sc.
  2. Examine the default StorageClass in your Kind cluster.
  3. Create a PVC that uses the default StorageClass - storage is provisioned dynamically.
  4. Apply dynamic-pvc.yaml and dynamic-pod.yaml.
  5. Write a file in the dynamically provisioned volume, then read it back.
  6. 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 1

kubectl get sc
kubectl describe sc standard

Hint 2

Apply and check:

kubectl apply -f dynamic-pvc.yaml
kubectl apply -f dynamic-pod.yaml
kubectl get pv,pvc

Hint 3

The password is storclass.


🔓 Unlock Room 26

openssl enc -aes-256-cbc -d -a -pbkdf2 \
        -in ../room_26/README             \
        -out ../room_26/README.txt        \
        -pass pass:PASSWORD
cat ../room_26/README.txt