Configuring Storage Classes

1. Creating StorageClass

Example: AWS gp3 SC

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata: { name: gp3 }
provisioner: ebs.csi.aws.com
parameters:
  type: gp3
  iops: "3000"
  throughput: "125"
  encrypted: "true"
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete
allowVolumeExpansion: true
mountOptions: [discard]

2. Listing StorageClasses

kubectl get sc
kubectl get sc -o jsonpath='{.items[?(@.metadata.annotations.storageclass\.kubernetes\.io/is-default-class=="true")].metadata.name}'
ColumnMeaning
PROVISIONERCSI driver/in-tree plugin
RECLAIMPOLICYDefault for new PVs
VOLUMEBINDINGMODEImmediate / WaitForFirstConsumer

3. Setting Default StorageClass

kubectl patch sc gp3 -p '{"metadata":{"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
kubectl patch sc gp2 -p '{"metadata":{"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
RuleDetail
One defaultOnly one SC should be default per cluster
FallbackPVCs without storageClassName use default

4. Configuring Provisioners

ProvisionerDriver
AWS EBSebs.csi.aws.com
GCE PDpd.csi.storage.gke.io
Azure Diskdisk.csi.azure.com
NFSnfs.csi.k8s.io / k8s-sigs.io/nfs-subdir-external-provisioner
Cephrook-ceph.rbd.csi.ceph.com
Localkubernetes.io/no-provisioner

5. Setting Volume Binding Mode

ModeBehavior
ImmediatePV provisioned at PVC create (default)
WaitForFirstConsumerWait for Pod scheduling; honors zone/topology
Note: Use WaitForFirstConsumer for zone-pinned volumes (EBS) to avoid scheduling pods into wrong AZ.

6. Configuring Reclaim Policy

ValueWhen PVC Deleted
DeletePV + underlying volume removed
RetainPV kept; manual cleanup

7. Enabling Volume Expansion

allowVolumeExpansion: true
RequirementDetail
CSI supportDriver must implement EXPAND_VOLUME
FS resizeAutomatic when pod restarts (ext4, xfs)

8. Using Storage Parameters

ProviderCommon parameters
AWStype, iops, throughput, encrypted, kmsKeyId
GCEtype, replication-type
AzureskuName, kind, location
NFSserver, path, mountOptions

9. Configuring Mount Options

mountOptions:
- discard          # trim for SSDs
- noatime
- nfsvers=4.2
Common OptionUse
discardAuto-TRIM for SSDs
noatimeReduce metadata writes
nolockNFS without file locking

10. Deleting StorageClasses

kubectl delete sc gp2
Warning: Existing PVs/PVCs are unaffected; new PVCs referencing the SC will hang Pending.