Stay organized with collections Save and categorize content based on your preferences.
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.
For more information on volume expansion, see the open source Kubernetes documentation.
PrerequisitesVolume expansion has the following prerequisites:
ReadOnlyMany
access mode.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 file system to be incorrect. To fix these issues, see troubleshoot volume expansion changes.
Managing volume expansions in StatefulSetsIf you need to increase the size of volumes used by Pods within a StatefulSet in Kubernetes, you should adjust the spec.resources.requests.storage
field of the PersistentVolumeClaims (PVCs) associated with the Pods. Attempting to modify the volumeClaimTemplates
field directly in the StatefulSet object will cause an error.
Additionally, if you increase the replica count of the StatefulSet, it will still create PVCs of the original size. To permanently change the size of the volumes provisioned for the Pods managed by the StatefulSet, you must delete and recreate the StatefulSet object with the updated size that's specified in the volumeClaimTemplates
field.
You can perform the following steps in order to keep the original Pods up and running while adjusting the StatefulSet to provision future replicas with the new volume size.
Save the existing StatefulSet to a file:
kubectl get StatefulSet statefulset-name -o yaml > sts-backup.yaml
For each PersistentVolumeClaim in the StatefulSet, open the PersistentVolumeClaim
object in a text editor:
kubectl edit pvc PVC_NAME
Update the spec.resources.requests.storage
field to the new volume size, like in the following example:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
# lines omitted for clarity
spec:
resources:
requests:
storage: 14Gi
# lines omitted for clarity
For details, see Expanding Persistent Volumes Claims.
Save your edits and close the text editor. Wait for Kubernetes to update the PersistentVolumeClaim with your changes.
Remove the StatefulSet object from the cluster while keeping the Pods running as standalone Pods:
kubectl delete sts statefulset-name --cascade=orphan
Edit the new volume storage size in the locally saved sts-backup.yaml
file, specifically the value of spec.volumeClaimTemplates.spec.resources.requests.storage
Recreate the StatefulSet back in the cluster:
kubectl apply -f sts-backup.yaml
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-12 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-12 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4