StorageClasses, CSI and dynamic provisioning

Intermediate · 4 min

How a claim becomes a real disk on demand: StorageClasses, the default class, WaitForFirstConsumer, CSI drivers and sidecars, and VolumeAttributesClass.

Before thisPersistentVolumes and PersistentVolumeClaims

Tech Tutorials with Piyush · 12 min · from 8:30

StorageClasses, CSI and dynamic provisioning

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Tech Tutorials with PiyushReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A StorageClass names a provisioner and its parameters. A claim that names the class (or gets the default class) causes a PV to be created for it on demand.
  • volumeBindingMode WaitForFirstConsumer delays provisioning until a Pod is scheduled, so the disk is created in the Pod's zone. Immediate can strand a zonal disk where the Pod can't run.
  • Storage drivers are CSI drivers outside Kubernetes: a controller plugin with sidecars (external-provisioner, -attacher, -resizer, -snapshotter) and a node plugin DaemonSet that mounts volumes.
  • The in-tree cloud disk plugins are gone. Cloud volumes now need the cloud's CSI driver, and only a few generic in-tree plugins such as nfs, iscsi and local remain.
  • StorageClass parameters are immutable. VolumeAttributesClass (GA in 1.34) lets you change a volume's IOPS or throughput tier on a live claim.

Nobody wants to file a ticket for a disk

With static provisioning, an admin creates PersistentVolumes ahead of time and claims pick from the pool. That works for a handful of volumes. It falls apart when every team, every StatefulSet replica and every test environment wants its own disk, in its own size, right now. You either keep a large pool of idle disks or someone is creating EBS volumes by hand all day.

Dynamic provisioning turns it around: the claim causes the volume. A StorageClass describes a kind of storage and who can make it, and when a claim asks for that class, a provisioner creates a disk of the right size and a PV for it. It’s the difference between a hotel with fixed rooms and a builder who puts up a room to the guest’s spec as they arrive.

The StorageClass

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: gp3
  annotations: {storageclass.kubernetes.io/is-default-class: "true"}
provisioner: ebs.csi.aws.com
parameters: {type: gp3, encrypted: "true"}
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true

provisioner names the driver. parameters are opaque to Kubernetes and passed to that driver: disk type, encryption, filesystem. reclaimPolicy becomes the reclaim policy of every PV it creates, Delete by default, so deleting the claim deletes the disk. allowVolumeExpansion lets claims grow later.

The default-class annotation matters more than it looks. An admission plugin fills the default class into claims that don’t name one. Our claim pgdata asked only for 20Gi ReadWriteOnce and came back with storageClassName: gp3. Since 1.28, claims created while no default existed get one assigned retroactively once a default appears. To opt out of dynamic provisioning, a claim sets storageClassName: "". Classes are also immutable where it counts: patching parameters on gp3 was refused with field is immutable.

Binding mode and topology

Most cloud disks are zonal. An EBS volume in eu-b can only attach to a node in eu-b. That’s why volumeBindingMode matters:

  • Immediate provisions as soon as the claim exists, in whatever zone the driver picks. If the Pod later can’t run in that zone (no capacity, affinity rules), it’s stuck.
  • WaitForFirstConsumer waits until a Pod using the claim is scheduled, then provisions in that node’s zone.

We traced the second path step by step on the lab cluster. The new claim sat Pending with the event WaitForFirstConsumer: waiting for first consumer to be created before binding. When we created a Pod using it, the scheduler’s volume-binding plugin chose node w2 and wrote volume.kubernetes.io/selected-node: w2 onto the claim, and the PV controller added volume.kubernetes.io/storage-provisioner: ebs.csi.aws.com and the event Waiting for a volume to be created either by the external provisioner 'ebs.csi.aws.com' or manually by the system administrator. That’s where Kubernetes’s own job ends. With no driver installed, we played the provisioner: we created a PV with a csi source, a claimRef to the claim and nodeAffinity for zone eu-b. The PV controller bound it at once, and the Pod was scheduled onto w2.

Then the attach step. Once the Pod was on w2, the attach-detach controller created a VolumeAttachment object (ATTACHER ebs.csi.aws.com, NODE w2, ATTACHED false) asking for the disk to be attached to that node. It only did so after we set the controller-managed-attach-detach annotation that a real kubelet sets on its Node. A real CSI driver’s external-attacher would then call the cloud API and flip ATTACHED to true.

CSI: drivers outside the tree

Storage drivers used to be compiled into Kubernetes, one per cloud and vendor. Every fix waited on a Kubernetes release. The Container Storage Interface is a gRPC spec that moves drivers out of tree. A CSI driver usually ships as two parts:

  • A controller plugin, a Deployment, which creates, deletes, attaches, expands and snapshots volumes through the storage system’s API. Kubernetes-maintained sidecars sit next to it and translate API objects into CSI calls: external-provisioner watches claims and calls CreateVolume, external-attacher watches VolumeAttachments and calls ControllerPublishVolume, and external-resizer and external-snapshotter handle expansion and snapshots.
  • A node plugin, a DaemonSet, which the kubelet calls (through a socket registered by node-driver-registrar) to format, stage and mount the volume into the Pod (NodeStageVolume, NodePublishVolume).

A CSIDriver object tells Kubernetes how the driver behaves (does it need attaching, does it want Pod info on mount), and CSINode objects record which drivers each node runs and how many volumes it can take.

The move is finished. The v1.37.3 source tree’s pkg/volume still has plugins for nfs, iscsi, fc, local, hostPath and the API-backed volumes. The AWS, GCE, Azure, OpenStack and vSphere disk plugins are gone. Old kubernetes.io/aws-ebs classes are migrated to the CSI driver, which must be installed. On a new cloud cluster, installing (or enabling the managed add-on for) the CSI driver is a day-one task.

Changing a live volume

Since StorageClass parameters are fixed at creation, how do you move a database to faster disk without copying data? A VolumeAttributesClass, GA since 1.34, holds mutable parameters such as IOPS and throughput:

apiVersion: storage.k8s.io/v1
kind: VolumeAttributesClass
metadata: {name: fast-iops}
driverName: ebs.csi.aws.com
parameters: {iops: "8000", throughput: "500"}

Setting volumeAttributesClassName: fast-iops on the bound claim was accepted, and kubectl get pvc showed the new class in its VOLUMEATTRIBUTESCLASS column. The external-resizer then calls the driver’s ControllerModifyVolume, and the claim’s modifyVolumeStatus reports progress. Without a driver, nothing progressed. Not every driver supports modification. Check yours.

About the video

The embed is a 12-minute clip, 8:30 to 20:30, of Tech Tutorials with Piyush’s “Day 52 - Storage Classes in Kubernetes | Static vs Dynamic Volume Provisioning”, June 2025. The clip covers the limits of static provisioning, what StorageClasses are with a demo, a dynamic provisioning demo, its benefits, and a static-versus-dynamic comparison. It covers the “what” well and says little about CSI internals, binding modes or VolumeAttributesClass, which this lesson covers from the lab and docs. Judged from chapters, since transcripts can’t be fetched here. It has no audio-track flag and an English caption track. Civo’s 2021 talk in deeper looks inside a CSI driver.

What was run: against a local v1.37.3 control plane with no kubelet and no CSI driver, we created the StorageClass, CSIDriver and claim, saw the default class filled in and the WaitForFirstConsumer event, watched the scheduler write selected-node and the PV controller hand off to the external provisioner, created the PV ourselves in the provisioner’s place, saw it bind and the Pod schedule, watched the attach-detach controller create a VolumeAttachment, and set a VolumeAttributesClass on the claim. CSI calls and sidecar behaviour are from the Kubernetes CSI docs and the CSI spec, checked 2026-11-28.

Where this fits

Dynamic volumes can also be grown, snapshotted and cloned. Next: volume snapshots, expansion and stateful data.

Check yourself

  1. 01A PVC with storageClassName gp3 stays Pending with the event 'waiting for first consumer to be created before binding'. Is something broken?

    No. The class uses WaitForFirstConsumer, so provisioning waits until a Pod that uses the claim is scheduled. Create the Pod and the scheduler records a selected node on the claim, then the provisioner creates the volume in that node's zone.

  2. 02With volumeBindingMode Immediate on a multi-zone cluster, a StatefulSet Pod is stuck unschedulable with a 'volume node affinity conflict'. Why?

    The disk was provisioned as soon as the claim was created, in whatever zone the provisioner picked. Zonal disks can only attach in their zone, and the Pod's other constraints keep it out of that zone. WaitForFirstConsumer avoids this by provisioning after the scheduler picks a node.

  3. 03A claim names a class whose provisioner is ebs.csi.aws.com, but nothing ever happens beyond 'Waiting for a volume to be created by the external provisioner'. What do you check?

    That the EBS CSI driver is installed and running: its controller Deployment (with the external-provisioner sidecar) and node DaemonSet, a CSIDriver object, and IAM permissions. Kubernetes core only annotates the claim. The driver does the provisioning.

  4. 04You want a running database volume to go from 3,000 to 8,000 IOPS. Why can't you edit the StorageClass, and what do you use?

    StorageClass parameters are immutable and only apply at creation. Create a VolumeAttributesClass with the new parameters and set volumeAttributesClassName on the claim. The external-resizer asks the driver to modify the live volume, if the driver supports it.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark