In this lesson, you will learn how to increase the storage capacity of your existing Persistent Volumes (PVs) without interrupting your running applications.
The Problem: Running Out of Space
As your application grows, the data stored in your Persistent Volume Claims (PVCs) might eventually hit its limit. Traditionally, increasing storage might have required unmounting volumes, shutting down pods, or even migrating data to a new, larger disk. However, Kubernetes supports Online Volume Expansion, which allows you to grow your storage while the application remains live and continues reading or writing data.
Enabling Online Expansion
For this to work, your underlying StorageClass must explicitly support volume expansion. You verify this by checking if the allowVolumeExpansion field is set to true:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: standard-fast
provisioner: kubernetes.io/aws-ebs
allowVolumeExpansion: true
Expanding the Volume
Once your StorageClass is configured, increasing the capacity is a simple operation. You simply update the spec.resources.requests.storage field in your existing PVC manifest to the new, larger value:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-app-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi # Previously 10Gi, now updated to 20Gi
When you apply this change using kubectl apply, Kubernetes communicates with your cloud provider or storage driver to resize the physical disk. Because it is an online operation, the Kubernetes file system controller expands the filesystem automatically once the disk size has been increased by the infrastructure. Your pods do not need to be restarted, and there is no downtime for your users; the application simply sees a larger disk partition appear over time.
Note that this only works for increasing size, not decreasing it. Always ensure your underlying storage provider supports this feature before relying on it in production!
Key Takeaway: By setting allowVolumeExpansion: true in your StorageClass, you can grow your storage capacity on-the-fly by simply updating the PVC request, ensuring your applications scale seamlessly without service interruption.