In Google Kubernetes Engine (GKE) version 1.24 or later, you can use the Kubernetes volume expansion feature to change a persistent volume's capacity after its creation.
Prerequisites
Volume expansion has the following prerequisites:
- If the volume you want to resize is managed by a CSI Driver:
- Ensure the GKE cluster version is 1.16 or later. If the cluster has Windows node pools, ensure the GKE cluster version is 1.18 or later. If you are using the managed GKE Filestore CSI driver, the cluster version must be 1.21 or later.
- Check your storage vendor's documentation to verify your CSI driver supports volume expansion. The Compute Engine persistent disk CSI driver and the Filestore CSI driver support volume expansion.
- If the volume you want to resize is managed by an in-tree volume plugin:
- Ensure the GKE cluster version is 1.11 or greater. While GKE cluster versions 1.11-1.14 support expansion of volumes managed by in-tree plugins, they require all Pods using the volume to be terminated and recreated to complete volume expansion.
- Check your storage vendor's documentation to verify your in-tree volume plugin supports volume expansion (the Compute Engine persistent disk in-tree plugin does).
Using volume expansion
To use volume expansion, perform the following tasks:
Add
allowVolumeExpansion: true
to your StorageClass, if your StorageClass doesn't already have the field. For example:apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: standard provisioner: my.driver ... allowVolumeExpansion: true
Request a change in volume capacity by editing your PersistentVolumeClaim's
spec.resources.requests.storage
field.kubectl edit pvc pvc-name
For example, you could change the following PVC from having a 30 gibibyte (GiB) disk to having a 40 GiB disk.
Before editing:
# pvc-demo.yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-demo spec: accessModes: - ReadWriteOnce resources: requests: storage: 30Gi
After editing:
# pvc-demo.yaml apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-demo spec: accessModes: - ReadWriteOnce resources: requests: storage: 40Gi
Verify the change by viewing PVC. To view your PVC, run the following command:
kubectl get pvc pvc-name -o yaml
Eventually, you should see the new volume in the
status.capacity
field. For example:... spec: accessModes: - ReadWriteOnce resources: requests: storage: 40Gi storageClassName: standard volumeMode: Filesystem volumeName: pvc-078b7484-cc8d-4077-9bcb-2c17d8d4550c status: accessModes: - ReadWriteOnce capacity: storage: 40Gi ...
If the capacity of a PersistentVolume is modified directly, this could lead the container filesystem to be incorrect. To fix these issues, see troubleshoot volume expansion changes.
What's next
- Learn more about volumes.
- Learn more about Resizing Persistent Volumes using Kubernetes.