StorageClass
A StorageClass is the cluster-wide template the dynamic provisioner uses to satisfy a PersistentVolumeClaim. It encodes WHICH backend (EBS, PD, Azure Disk, Ceph, NFS), WHAT parameters (type, IOPS, encryption), HOW reclaim works, and WHEN binding happens. Without a default StorageClass and at least one named one, every stateful Helm chart breaks on install.
Default + named StorageClasses with sensible knobs
EXAMPLE
# 1) Default StorageClass — what PVCs without a storageClassName use
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: standard-rwo
annotations:
storageclass.kubernetes.io/is-default-class: 'true'
provisioner: ebs.csi.aws.com # or pd.csi.storage.gke.io, disk.csi.azure.com
parameters:
type: gp3
fsType: ext4
encrypted: 'true'
reclaimPolicy: Delete # Retain if you want the volume to outlive the PVC
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer
---
# 2) High-IOPS StorageClass for databases
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata: { name: db-high-iops }
provisioner: ebs.csi.aws.com
parameters:
type: io2
iops: '6000'
fsType: ext4
encrypted: 'true'
reclaimPolicy: Retain # NEVER auto-delete DB volumes
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer
---
# 3) Local-ssd class for ephemeral, fastest-possible caches
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata: { name: local-ssd }
provisioner: ebs.csi.aws.com
parameters: { type: gp3, fsType: xfs }
reclaimPolicy: Delete
allowVolumeExpansion: false
volumeBindingMode: WaitForFirstConsumer
---
# 4) ReadWriteMany class via EFS / NFS for shared assets
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata: { name: shared-rwx }
provisioner: efs.csi.aws.com
parameters:
provisioningMode: efs-ap
fileSystemId: fs-0123456789abcdef0
directoryPerms: '0755'
mountOptions: ['tls', 'iam']
reclaimPolicy: Retain
volumeBindingMode: Immediate # EFS is region-wide, zone affinity moot
---
# 5) PVCs reference a class by name (or omit to use the default)
apiVersion: v1
kind: PersistentVolumeClaim
metadata: { name: pg-data, namespace: shop }
spec:
storageClassName: db-high-iops
accessModes: [ReadWriteOnce]
resources: { requests: { storage: 100Gi } }
# 6) Inspect classes and which is the default
kubectl get storageclass
kubectl describe storageclass standard-rwo
kubectl get pvc -A -o custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name,CLASS:.spec.storageClassName,STATUS:.status.phase
# 7) Change the default safely
kubectl annotate storageclass standard-rwo storageclass.kubernetes.io/is-default-class='false' --overwrite
kubectl annotate storageclass db-high-iops storageclass.kubernetes.io/is-default-class='true' --overwrite
Why it matters
Set reclaimPolicy: Retain on every storage class that backs durable data (databases, message queues, anything with WAL). The PVC delete that fires during a misclick or a `helm uninstall` then leaves the underlying volume behind, recoverable. Delete is the right policy only for genuinely disposable caches.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Discussion
Loading…