πŸ“šBook Signing at KubeCon EU 2026Meet us at Booking.com HQ (Mon 18:30-21:00) & vCluster booth #521 (Tue 24 Mar, 12:30-1:30pm) β€” free book giveaway!RSVP Booking.com Event
Storage intermediate ⏱ 20 minutes K8s 1.28+

Storage Classes and Provisioners

Configure Kubernetes StorageClasses for dynamic volume provisioning. CSI drivers, reclaim policies, volume expansion, topology-aware provisioning.

By Luca Berton β€’ β€’ πŸ“– 5 min read

πŸ’‘ Quick Answer: Create StorageClasses with reclaimPolicy: Retain for databases (preserves data on PVC deletion), allowVolumeExpansion: true for growing volumes, and volumeBindingMode: WaitForFirstConsumer for topology-aware scheduling. Use Retain for production, Delete for dev.

The Problem

The default StorageClass with reclaimPolicy: Delete destroys your data when a PVC is deleted. Without allowVolumeExpansion, you can’t grow volumes without recreating them. And Immediate binding breaks topology-aware scheduling β€” pods can’t reach volumes provisioned in the wrong zone.

The Solution

Production StorageClass

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast-ssd
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"
provisioner: ebs.csi.aws.com
parameters:
  type: gp3
  iops: "3000"
  throughput: "125"
  encrypted: "true"
  fsType: ext4
reclaimPolicy: Retain
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer
mountOptions:
  - noatime

Storage Class Comparison

PurposeReclaimExpansionBindingType
Database (prod)RetaintrueWaitForFirstConsumergp3/io2
App cache (prod)DeletetrueWaitForFirstConsumergp3
Dev/testDeletetrueImmediategp3
AI model storageRetaintrueWaitForFirstConsumerio2

High-Performance AI Storage

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: ai-model-storage
provisioner: ebs.csi.aws.com
parameters:
  type: io2
  iops: "64000"
  encrypted: "true"
reclaimPolicy: Retain
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer

NFS StorageClass (ReadWriteMany)

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nfs-shared
provisioner: nfs.csi.k8s.io
parameters:
  server: nfs.example.com
  share: /exports/kubernetes
reclaimPolicy: Retain
mountOptions:
  - nfsvers=4.1
  - hard
  - nconnect=8
graph TD
    PVC[PVC Request<br/>storageClassName: fast-ssd] --> SC[StorageClass<br/>fast-ssd]
    SC -->|WaitForFirstConsumer| SCHED[Pod scheduled<br/>to node in zone-a]
    SCHED --> PROV[CSI Driver<br/>provisions volume<br/>in zone-a]
    PROV --> PV[PV created<br/>gp3, 3000 IOPS]
    PV --> BOUND[PVC Bound βœ…]
    
    DEL[PVC Deleted] --> RETAIN[PV retained<br/>Data preserved]

Common Issues

PVC stuck in Pending

Check events: kubectl describe pvc. Common causes: no CSI driver installed, wrong StorageClass name, or no capacity in the zone.

Volume provisioned in wrong zone β€” pod can’t mount

Use volumeBindingMode: WaitForFirstConsumer instead of Immediate. This delays provisioning until the pod is scheduled.

Best Practices

  • Retain for production data β€” never lose data on accidental PVC deletion
  • WaitForFirstConsumer always β€” ensures volume is in the same zone as the pod
  • allowVolumeExpansion: true β€” lets you grow volumes without recreation
  • Separate StorageClasses for different workloads β€” databases vs cache vs AI models
  • Encrypt all volumes β€” encrypted: true parameter for cloud CSI drivers

Key Takeaways

  • StorageClass controls how volumes are dynamically provisioned
  • reclaimPolicy: Retain preserves data when PVC is deleted β€” essential for databases
  • WaitForFirstConsumer ensures volumes are provisioned in the correct topology zone
  • allowVolumeExpansion: true enables growing volumes without recreation
  • Create separate StorageClasses for different performance tiers and workload types
#storage-class #csi #persistent-volume #dynamic-provisioning
Luca Berton
Written by Luca Berton

Principal Solutions Architect specializing in Kubernetes, AI/GPU infrastructure, and cloud-native platforms. Author of Kubernetes Recipes and creator of CopyPasteLearn courses.

Kubernetes Recipes book cover

Want More Kubernetes Recipes?

This recipe is from Kubernetes Recipes, our 750-page practical guide with hundreds of production-ready patterns.

Luca Berton Ansible Pilot Ansible by Example Open Empower K8s Recipes Terraform Pilot CopyPasteLearn ProteinLens