Default StorageClass
A PVC does not name a StorageClass, so where does it get one, and why does storageClassName: "" behave differently from leaving the field out? Left out, the DefaultStorageClass admission plugin writes in the class annotated as default at creation, and if none exists yet the PV binding controller writes it into the still unbound claim once one appears. An empty string asks for no class, so both leave it alone and it binds only to a classless volume.
Play the animation 5 steps, animated, best on a wide screen
Default StorageClass, step by step
-
PVC data-a leaves storageClassName out. On its way into the API server the DefaultStorageClass admission plugin looks for the class annotated storageclass.kubernetes.io/is-default-class: "true", finds standard, and writes it into the claim before the claim is stored.
Play from step 1 -
PVC data-b sets storageClassName: "" on purpose. An empty string is a value, so the plugin leaves it alone: the claim asks for no class at all. The binding controller can pair it only with a volume that has no class either, here the pre-created PV nfs-01.
Play from step 2 -
To switch defaults the admin first removes the annotation from standard. PVC data-c, created in that gap, gets no class written in. A claim like it could still bind a volume that has no class, but nfs-01 is already bound, so data-c waits Pending with no class.
Play from step 3 -
Then the admin annotates fast. On its periodic resync, every 15 seconds by default, the PV binding controller writes the new default into each unbound claim that still has no storageClassName and matched no volume, so data-c gets fast. The empty string on data-b stays, and data-a keeps standard: a class, once written, does not follow the default.
Play from step 4 -
The other order annotates the new class before removing the old flag, so for a short migration window fast and ultra are both default. PVC data-d, created in that window, gets the most recently created of the two: ultra. Outside a migration, keep just one default.
Play from step 5