Default StorageClass
What You'll Learn
You'll learn how to configure a default StorageClass so that PersistentVolumeClaims without an explicit storage class are automatically provisioned.
The Problem Without a Default
When you create a PersistentVolumeClaim (PVC), you can specify which StorageClass to use. But what happens if you don't specify one? Without a default StorageClass, the PVC would remain unbound indefinitely—there's no provisioner to create the PersistentVolume automatically.
How Default StorageClasses Work
A default StorageClass acts as the automatic choice when a PVC doesn't specify storageClassName. Think of it like setting a default printer: if you don't choose a specific printer when printing, your document goes to the default one.
To mark a StorageClass as default, add this annotation:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: standard
annotations:
storageclass.kubernetes.io/is-default-class: "true"
provisioner: kubernetes.io/aws-ebs
parameters:
type: gp2
Now when you create a PVC without specifying storageClassName, Kubernetes automatically uses this default:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
# No storageClassName specified—uses default!
Important Notes
- Only one StorageClass should be marked as default in a cluster
- If you explicitly set
storageClassName: ""in a PVC, it opts out of dynamic provisioning entirely (static binding only) - Many managed Kubernetes services (EKS, GKE, AKS) come with a default StorageClass pre-configured
Key Takeaway: Setting a default StorageClass with the is-default-class annotation provides automatic dynamic provisioning for PVCs that don't explicitly specify a storage class, simplifying storage configuration for common use cases.