Default StorageClass

A PVC without storageClassName can still end up with a StorageClass, while one with an empty string there never does. Who writes the class into the first, why not the second, and which wins if two classes are default?

Play the animation 5 steps, animated, plays on a computer or a tablet

Default StorageClass, Kubernetes diagram

Default StorageClass, step by step

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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, there should be just one default.

    Play from step 5

Sources