Volume Expansion with StorageClasses
What You'll Learn
You'll learn how to enable and perform on-the-fly expansion of persistent volumes without disrupting your running applications.
The Core Idea
Sometimes your application's storage needs grow over time—your database gets bigger, your logs accumulate, or user uploads increase. Rather than creating a new, larger volume and migrating data, Kubernetes can expand existing volumes dynamically using the allowVolumeExpansion setting in your StorageClass.
Think of it like elastic waistband pants: instead of buying new pants when you need more room, the waistband stretches to accommodate you. Similarly, your volume grows without replacement.
How It Works
When you create a StorageClass, you can set allowVolumeExpansion: true. This tells Kubernetes: "Volumes created from this StorageClass can be resized later."
Here's what a StorageClass with expansion enabled looks like:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: expandable-storage
provisioner: kubernetes.io/aws-ebs
parameters:
type: gp2
allowVolumeExpansion: true
To expand a volume, you simply edit your PVC and increase the storage request:
spec:
resources:
requests:
storage: 20Gi # Previously was 10Gi
Kubernetes and the underlying storage provider handle the rest. Some expansions happen online (while the Pod is running), while others require a Pod restart—it depends on your storage backend and filesystem type.
Important Considerations
- Not all storage providers support expansion (check your cloud provider's CSI driver)
- You can only increase size, never decrease
- File system expansion may require a Pod restart to take effect
Key Takeaway: Enable allowVolumeExpansion: true in your StorageClass to allow PVCs to grow dynamically by editing their storage request, eliminating the need for data migration when you need more space.