Skip to content

🎓 LEVEL 35 DEBRIEF: StorageClass Configuration

Congratulations! You've mastered StorageClass troubleshooting - the foundation of dynamic storage provisioning in Kubernetes!


📊 What You Fixed

The Problem:

spec:
  storageClassName: premium-ssd  # ❌ Doesn't exist!
Result: PVC stuck in Pending forever

The Solution:

spec:
  storageClassName: standard  # ✅ Use existing StorageClass
Result: PVC automatically provisioned and bound


🔍 Understanding StorageClass

What is a StorageClass?

StorageClass is a Kubernetes resource that describes different "classes" of storage: - Provisioner: What creates the storage (AWS EBS, GCE PD, NFS, etc.) - Parameters: Configuration (disk type, IOPS, encryption, etc.) - Reclaim Policy: What happens when PVC is deleted - Volume Binding Mode: When to provision (Immediate or WaitForFirstConsumer)

Static vs Dynamic Provisioning

Static Provisioning (Manual): 1. Admin creates PersistentVolume manually 2. User creates PVC 3. Kubernetes binds PVC to matching PV

Dynamic Provisioning (Automatic): 1. User creates PVC with storageClassName 2. StorageClass provisioner automatically creates PV 3. Kubernetes binds PVC to new PV


🎯 StorageClass Examples

AWS EBS (Block Storage)

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast-ebs
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp3
  iopsPerGB: "10"
  encrypted: "true"
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer

Google Cloud Persistent Disk

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast-gce
provisioner: kubernetes.io/gce-pd
parameters:
  type: pd-ssd
  replication-type: regional-pd

Azure Disk

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: fast-azure
provisioner: kubernetes.io/azure-disk
parameters:
  storageaccounttype: Premium_LRS
  kind: Managed

NFS (Network File System)

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nfs-storage
provisioner: example.com/nfs
parameters:
  server: nfs-server.example.com
  path: /exported/path
  readOnly: "false"

💥 Common Mistakes

Mistake 1: Non-Existent StorageClass

# PVC
spec:
  storageClassName: super-fast  # ❌ Doesn't exist!
Fix: Use kubectl get sc to find available classes

Mistake 2: Wrong Provisioner for Cloud

# On AWS, but using GCE provisioner
kind: StorageClass
provisioner: kubernetes.io/gce-pd  # ❌ Wrong cloud!
Fix: Match provisioner to your infrastructure

Mistake 3: Missing Default StorageClass

# No default marked, PVCs with empty storageClassName fail
Fix: Mark one as default:
metadata:
  annotations:
    storageclass.kubernetes.io/is-default-class: "true"


🚨 REAL-WORLD INCIDENT: The Missing StorageClass

Company: E-commerce platform Impact: 2 hours downtime, $400K revenue loss

What Happened: - New developer created PVC with storageClassName: fast-storage - StorageClass didn't exist - Deployment stuck, pods couldn't start - Black Friday traffic lost

Root Cause: No validation of StorageClass existence

Fix: - Document available StorageClasses - Add admission webhook to validate - Create standard storage classes in all environments


🛡️ Best Practices

  1. List available classes:

    kubectl get storageclass
    

  2. Set a default:

    annotations:
      storageclass.kubernetes.io/is-default-class: "true"
    

  3. Use WaitForFirstConsumer for multi-zone:

    volumeBindingMode: WaitForFirstConsumer
    # Ensures PV created in same zone as pod
    

  4. Document your classes:

    metadata:
      annotations:
        description: "Fast SSD storage for databases"
        cost: "high"
        performance: "high-iops"
    


🎯 Key Takeaways

  1. StorageClass enables dynamic provisioning - No manual PV creation
  2. Must exist before PVC creation - Or PVC stays Pending
  3. Different classes for different needs - Fast/slow, cheap/expensive
  4. Cloud-specific provisioners - AWS EBS, GCE PD, Azure Disk
  5. Check availability first - kubectl get sc

Well done! You understand StorageClass fundamentals! 🎉