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}'
| Column | Meaning |
| PROVISIONER | CSI driver/in-tree plugin |
| RECLAIMPOLICY | Default for new PVs |
| VOLUMEBINDINGMODE | Immediate / 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"}}}'
| Rule | Detail |
| One default | Only one SC should be default per cluster |
| Fallback | PVCs without storageClassName use default |
4. Configuring Provisioners
| Provisioner | Driver |
| AWS EBS | ebs.csi.aws.com |
| GCE PD | pd.csi.storage.gke.io |
| Azure Disk | disk.csi.azure.com |
| NFS | nfs.csi.k8s.io / k8s-sigs.io/nfs-subdir-external-provisioner |
| Ceph | rook-ceph.rbd.csi.ceph.com |
| Local | kubernetes.io/no-provisioner |
5. Setting Volume Binding Mode
| Mode | Behavior |
| Immediate | PV provisioned at PVC create (default) |
| WaitForFirstConsumer | Wait 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
| Value | When PVC Deleted |
| Delete | PV + underlying volume removed |
| Retain | PV kept; manual cleanup |
7. Enabling Volume Expansion
allowVolumeExpansion: true
| Requirement | Detail |
| CSI support | Driver must implement EXPAND_VOLUME |
| FS resize | Automatic when pod restarts (ext4, xfs) |
8. Using Storage Parameters
| Provider | Common parameters |
| AWS | type, iops, throughput, encrypted, kmsKeyId |
| GCE | type, replication-type |
| Azure | skuName, kind, location |
| NFS | server, path, mountOptions |
9. Configuring Mount Options
mountOptions:
- discard # trim for SSDs
- noatime
- nfsvers=4.2
| Common Option | Use |
| discard | Auto-TRIM for SSDs |
| noatime | Reduce metadata writes |
| nolock | NFS without file locking |
10. Deleting StorageClasses
Warning: Existing PVs/PVCs are unaffected; new PVCs referencing the SC will hang Pending.