Appearance
Kubernetes Default Storage Class: How It Works
What is the role of a Default StorageClass?
The Core Role: The "Fallback" Provisioner
The primary role of a default StorageClass is to enable Dynamic Provisioning for PersistentVolumeClaims (PVCs) that do not specify any particular storage requirement. It acts as the "standard" tier of storage for the cluster.
- Simplifying User Experience: It allows users to request storage without needing to know the specific names of the StorageClasses available in the cluster. A user simply requests
storage: 10Gi, and the cluster provides a volume backed by the default class (e.g., standard SSDs). - Automatic Injection: When a user creates a PVC and leaves the
storageClassNamefield unspecified (nil), the DefaultStorageClass admission controller automatically injects the name of the default StorageClass into the PVC specification.
How It Works
- Configuration: Administrators mark a specific StorageClass as the default by setting the annotation
storageclass.kubernetes.io/is-default-classto"true". - Admission Control: The API server must have the
DefaultStorageClassadmission plugin enabled. This plugin watches for new PVC creation requests. - Binding:
- Unspecified Class: If a PVC has no
storageClassName, it gets the default. - Explicit Empty String: If a PVC explicitly sets
storageClassName: ""(empty string), the default is not applied. This is interpreted as a request for a static PersistentVolume (PV) with no class, effectively disabling dynamic provisioning for that specific claim.
- Unspecified Class: If a PVC has no
Operational Considerations
- Multiple Defaults: While possible to mark multiple classes as default, this is generally discouraged to avoid confusion. If multiple defaults exist, the admission controller creates the PVC using the most recently created default StorageClass.
- Retroactive Assignment: In newer Kubernetes versions (v1.28+), if a default StorageClass is created after a PVC was created (and that PVC was waiting in a Pending state because it had no class), the control plane can retroactively assign the new default class to the lingering PVC.
- Changing Defaults: You can change the default class by removing the annotation from the old class and adding it to the new one. This does not affect existing Bound PVCs, only new ones.