Skip to content
intermediate Phase 6 · Storage

StorageClasses

Configure StorageClasses for dynamic volume provisioning with different access modes.

1h
0 problems
Topic Progress 0%

Dynamic Provisioning on Demand

Dynamic Provisioning on Demand

Before StorageClasses, admins pre-created a finite pool of PVs and users waited for a fit. A class inverts that: the claim names a class, its provisioner creates the volume on demand, and binding happens immediately.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata: { name: fast-ssd }
provisioner: pd.csi.storage.gke.io
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true
parameters: { type: pd-ssd }

reclaimPolicy becomes the default for claims in the class; parameters are provisioner-specific and documented per CSI driver. Which classes exist depends on your cluster's drivers — copy the class only after confirming the provisioner is installed.

Binding Modes and Expansion

Binding Modes and Expansion

volumeBindingMode decides when provisioning runs:

  • Immediate — provision at claim creation. Fine for zone-agnostic storage; wrong for zonal disks, because the pod may schedule in another zone.
  • WaitForFirstConsumer — delay provisioning until a pod uses the claim, so topology constraints pick the correct zone. Recommended for zonal CSI disks.

Expansion flows through the chain when allowVolumeExpansion: true is set on the class (and the driver supports it):

kubectl edit pvc data    # raise spec.resources.requests.storage to 20Gi
kubectl get pvc data     # watch condition Resized=True

Shrinking is never permitted. Filesystem resize happens online for supported filesystems; some drivers still require a pod restart.

Pitfalls and Interview Angles

Pitfalls and Interview Angles

Pitfall 1 — Pending claims with no provisioner. Either the class does not exist, no default class carries the is-default-class: "true" annotation, or the CSI driver is not installed. kubectl describe pvc events name the failing class.

Pitfall 2 — zone mismatches with Immediate binding. A zonal disk created in zone A cannot attach to a node in zone B; pods stall in ContainerCreating with attach errors. Switch the class to WaitForFirstConsumer.

Interview-ready: contrast static PV pools with dynamic classes, explain why topology-aware binding exists, and describe expansion end to end — class flag, PVC size edit, Resized condition, and the explicit no-shrink rule.

Quiz

1. What does volumeBindingMode: WaitForFirstConsumer do?

Question 1 options

2. Can a 10Gi PVC be resized down to 5Gi?

Question 2 options

3. Why does a PVC stay Pending after adding a StorageClass?

Question 3 options

Flashcards

Question

StorageClass fields

Answer

provisioner, parameters, reclaimPolicy, volumeBindingMode, allowVolumeExpansion.

Question

Immediate vs WaitForFirstConsumer

Answer

Immediate provisions at claim time; WaitForFirstConsumer defers until a pod schedules (zone-safe).

Question

Default StorageClass

Answer

Class annotated storageclass.kubernetes.io/is-default-class: "true" satisfies claims with no storageClassName.

Question

Volume expansion rules

Answer

Needs class allowVolumeExpansion + driver support; growth only, never shrink.

Revision Notes

Key Takeaways

  • 1. Classes turn storage requests into automated provisioning
  • 2. Binding mode decides zone correctness for zonal disks
  • 3. Expansion is grow-only and travels class → claim → driver

Interview Tips

  • • Explain WaitForFirstConsumer with the zonal-disk scheduling story
  • • For "PVC Pending", give the three-check sequence: class, driver, events

Cheat Sheet

StorageClass = provisioner + params + reclaim + binding mode. WaitForFirstConsumer for zonal disks; default class via annotation. Expand only (never shrink).

Continue Learning