How to expand Kubernetes Physical Volume Claim (PVC)
Important note: By default, volumes will not be resized immediately but instead require a restart of the associated pod.
First, ensure that you have set allowVolumeExpansion: true
for the storage class of your PVC. See our previous post on How to allow Physical Volume Claim (PVC) resize for Kubernetes storage class for more details.
We can expand the volume (named myapp-myapp-pvc-myapp-myapp-1
in this example) by running
kubectl patch pvc/"myapp-myapp-pvc-myapp-myapp-1" \
--namespace "default" \
--patch '{"spec": {"resources": {"requests": {"storage": "40Gi"}}}}'
Ensure that you have replacedĀ the name of the PVC (myapp-myapp-pvc-myapp-myapp-1
in this example) and the storage size. It’s only possible to increase the size of the volume / expand it and not to downsize / shrink it. If your size is less than the previous value, you’ll see this error message:
The PersistentVolumeClaim "myapp-myapp-pvc-myapp-myapp-1" is invalid: spec.resources.requests.storage: Forbidden: field can not be less than previous value
After running this command, the PVC will be in the FileSystemResizePending
state.
In order for the update to have effect, you’ll need to force Kubernetes to re-create all the pods for your deployment. To find out how to do this, read our post onĀ How to force restarting all Pods in a Kubernetes Deployment.
For reference, see the official documentation on expanding persistent volumes