Volume Resizing and Expansion
Overview
You can now resize an existing volume by editing the PersistentVolumeClaim (PVC)
object. You no longer have to manually interact with the storage backend, or delete and recreate PV and PVC objects, to increase the size of a volume. Kubernetes will automatically expand the volume, using storage backend, and it will also expand the underlying file system in-use by the Pod, without requiring any downtime if the underlying storage provisioner can support it.
Prerequisites
-
Before performing an expansion, make sure that the source volume (PV) is provisioned dynamically, by adding the underlying source
storageClass
. If not, volume expansion fails. -
Make sure that underlying storage driver allows for volume expansion. Check the respective storage provider's documentation to verify.
Method
Perform volume expansion by editing the existing PersistentVolumeClaim (PVC)
object. You can expand the volume online or offline based on the specific storage driver support.
Online
Expands a PVC while the PVC is still in-use by the Pod.
- Pods referencing the resized volume do not need to be restarted. Instead, the file system will automatically be resized while in use as part of volume expansion.
Offline
Expanding a PVC which is not in-use by any Pod.
- If the underlying storage driver can only support offline expansion, users must take down their Pod before expanding the volume.
Note
-
File system expansion does not happen until a pod references the resized volume, so if no pods referencing the volume are running file system expansion does not happen.
-
Some storage drivers support Online expansion, some do not. Refer to the Storage driver list for your storage provider information.
Expanding the CTE-PVC Volume
You can use either command: kubectl patch
or kubectl edit
to expand the volume size.
-
Using the
kubectl patch
command:kubectl patch pvc <CTE-PVC_Name> -n <Namespace> --type merge -p '{"spec":{"resources":{"requests":{"storage":"<New_Size>"}}}}'
Example
This example requests expansion to 5G:
kubectl patch pvc cte-claim -n ns1 --type merge -p '{"spec":{"resources":{"requests":{"storage":"5Gi"}}}}'
-
Using the
kubectl edit
command:-
Type:
kubectl edit pvc
-n
Example
kubectl edit pvc cte-claim -n ns1
- Update the resource > request > storage field with the required size, for example 5Gi.
-
Validating volume expansion
The duration for volume expansion depends on the size of the new volume requested and the type of storage driver provisioner.
-
You can verify it by viewing the
cte-csi-controller-xxx
log:kubectl logs cte-csi-controller-6f669d4b94-8xdcl -n kube-system cte-csi
-
For more details, describe the CTE-PVC and sourcePVC. To verify this information, type:
kubectl describe pvc <pvc_name> -n <Namespace> kubectl get pvc <pvc_name> -n <Namespace> -o yaml
-
Watch the
status.conditions
field of the CTE-PVC, and sourcePVC, to see if the resize has completed. -
Refer to the storage driver documentation for more specific details.
Unsupported Functions
-
Shrinking persistent volumes is not supported.
-
Only dynamically provisioned PVCs whose storage class has the
allowVolumeExpansion
parameter set totrue
are expandable.