How to Expand Persistent Volume in Kubernetes: Step-by-Step Guide
To expand a
PersistentVolumeClaim in Kubernetes, update its spec.resources.requests.storage field with the new size and apply the change. Ensure the underlying storage class supports volume expansion and the allowVolumeExpansion flag is enabled.Syntax
To expand a Persistent Volume Claim (PVC), you modify the storage request in the PVC YAML under spec.resources.requests. The storage class used must support expansion and have allowVolumeExpansion: true.
After updating, Kubernetes will resize the volume if the underlying storage supports it.
yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi # New size here
storageClassName: standardExample
This example shows how to expand a PVC named my-pvc from 5Gi to 10Gi using kubectl. It assumes the storage class supports expansion.
bash
kubectl get pvc my-pvc
kubectl patch pvc my-pvc -p '{"spec":{"resources":{"requests":{"storage":"10Gi"}}}}'
kubectl get pvc my-pvcOutput
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
my-pvc Bound pvc-1234abcd-5678-efgh-ijkl-9012mnopqrst 5Gi RWO standard 10d
persistentvolumeclaim/my-pvc patched
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
my-pvc Bound pvc-1234abcd-5678-efgh-ijkl-9012mnopqrst 10Gi RWO standard 10d
Common Pitfalls
- Storage class does not support expansion: The PVC will not resize if
allowVolumeExpansionis false or missing. - Underlying storage limitations: Some storage backends do not allow resizing or require manual steps.
- Filesystem resize: After volume expansion, the filesystem inside the pod may need to be resized manually or the pod restarted.
yaml
### Wrong: Storage class without expansion apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: no-expand provisioner: kubernetes.io/aws-ebs allowVolumeExpansion: false ### Right: Enable expansion apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: expandable provisioner: kubernetes.io/aws-ebs allowVolumeExpansion: true
Quick Reference
- Check if your storage class supports expansion:
kubectl get sc <storageclass> -o yaml - Update PVC size with
kubectl patch pvcor edit YAML - Verify PVC size updated with
kubectl get pvc - Resize filesystem inside pod if needed
Key Takeaways
Ensure your storage class has allowVolumeExpansion set to true before resizing.
Update the PVC's storage request to the new size to trigger expansion.
Verify the PVC size change with kubectl after patching.
Some filesystems require manual resizing inside the pod after volume expansion.
Not all storage backends support dynamic volume expansion.