En la versión 1.24 y posteriores de Google Kubernetes Engine (GKE), puedes usar la función de expansión de volumen de Kubernetes para cambiar la capacidad de un volumen persistente después de su creación.
Para obtener más información sobre la expansión de volúmenes, consulta la documentación de Kubernetes de código abierto.
Requisitos previos
La expansión de volumen tiene los siguientes requisitos previos:
Si el volumen al que deseas cambiarle el tamaño lo administra un controlador de CSI:
Asegúrate de que la versión del clúster de GKE sea 1.16 o posterior.
Si el clúster tiene grupos de nodos de Windows, asegúrate de que la versión del clúster de GKE sea 1.18 o posterior.
Si usas el controlador de CSI de Filestore de GKE administrado, la versión del clúster debe ser 1.21 o posterior.
Consulta la documentación de tu proveedor de almacenamiento para verificar que tu controlador de CSI admita la expansión de volumen. El controlador de CSI de Persistent Disk de Compute Engine y el controlador de CSI de Filestore admiten la expansión de volumen.
Si el volumen al que deseas cambiarle el tamaño es administrado por un complemento de volumen de árbol:
Asegúrate de que la versión del clúster de GKE sea 1.11 o superior. Si bien las versiones 1.11 a 1.14 del clúster de GKE admiten la expansión de volúmenes administrados por complementos de árbol, también requieren que todos los pods que usan el volumen se cierren y se vuelvan a crear para completar la expansión del volumen.
Revisa la documentación de tu proveedor de almacenamiento para verificar que tu complemento de volumen de árbol admita la expansión de volumen (el complemento de árbol de Persistent Disk de Compute Engine lo hace).
Si la capacidad de un PersistentVolume se modifica directamente, esto podría hacer que el sistema de archivos del contenedor sea incorrecto. Para solucionar estos problemas, consulta Soluciona problemas de cambios en la expansión de volumen.
Administra las expansiones de volumen en StatefulSets
Si necesitas aumentar el tamaño de los volúmenes que usan los Pods dentro de un StatefulSet en Kubernetes, debes ajustar el campo spec.resources.requests.storage de las PersistentVolumeClaims (PVC) asociadas. con los Pods. Si intentas modificar el campo volumeClaimTemplates directamente en el objeto StatefulSet, se producirá un error.
Además, si aumentas el recuento de réplicas del StatefulSet, se seguirán creando PVC del tamaño original. A fin de cambiar de forma permanente el tamaño de los volúmenes aprovisionados para los Pods administrados por StatefulSet, debes borrar y volver a crear el objeto StatefulSet con el tamaño actualizado especificado en el campo volumeClaimTemplates.
Ten en cuenta que este proceso dará como resultado la eliminación de los Pods antiguos y sus PVCs correspondientes. Según la ReclaimPolicy, también es posible que se borre el almacenamiento subyacente.
Puedes seguir los pasos que se indican a continuación para mantener los Pods originales en funcionamiento mientras ajustas el StatefulSet para aprovisionar réplicas futuras con el nuevo tamaño de volumen.
Quita el objeto StatefulSet del clúster y mantén los Pods en ejecución como Pods independientes:
kubectldeletestsstatefulset-name--cascade=orphan
Edita el tamaño de almacenamiento del volumen nuevo en el archivo sts-backup.yaml guardado de forma local, específicamente el valor de spec.volumeClaimTemplates.spec.resources.requests.storage.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2024-12-21 (UTC)"],[],[],null,["# Using volume expansion\n\n[Autopilot](/kubernetes-engine/docs/concepts/autopilot-overview) [Standard](/kubernetes-engine/docs/concepts/choose-cluster-mode)\n\n*** ** * ** ***\n\nIn Google Kubernetes Engine (GKE) version 1.24 or later, you can use the Kubernetes\nvolume expansion feature to change a persistent volume's capacity after\nits creation.\n\nFor more information on volume expansion, see the open source\n[Kubernetes documentation](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#expanding-persistent-volumes-claims).\n\nPrerequisites\n-------------\n\nVolume expansion has the following prerequisites:\n\n- If the volume you want to resize is managed by a CSI Driver:\n - 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](/kubernetes-engine/docs/how-to/persistent-volumes/filestore-csi-driver), the cluster version must be 1.21 or later.\n - 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.\n- If the volume you want to resize is managed by an in-tree volume plugin:\n - 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.\n - 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).\n- You can't use volume expansion when using [`ReadOnlyMany` access mode](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes).\n\nUsing volume expansion\n----------------------\n\n| **Note:** To avoid errors using volume expansion, ensure that you complete the steps in this section in the right sequence.\n\nTo use volume expansion, perform the following tasks:\n\n1. Add `allowVolumeExpansion: true` to your StorageClass, if your StorageClass\n doesn't already have the field. For example:\n\n apiVersion: storage.k8s.io/v1\n kind: StorageClass\n metadata:\n name: standard\n provisioner: my.driver\n ...\n allowVolumeExpansion: true\n\n2. Request a change in volume capacity by editing your PersistentVolumeClaim's\n `spec.resources.requests.storage` field.\n\n kubectl edit pvc \u003cvar translate=\"no\"\u003epvc-name\u003c/var\u003e\n\n For example, you could change the\n following PVC from having a 30 gibibyte (GiB) disk to having a 40 GiB disk.\n\n Before editing: \n\n # pvc-demo.yaml\n apiVersion: v1\n kind: PersistentVolumeClaim\n metadata:\n name: pvc-demo\n spec:\n accessModes:\n - ReadWriteOnce\n resources:\n requests:\n storage: 30Gi\n\n After editing: \n\n # pvc-demo.yaml\n apiVersion: v1\n kind: PersistentVolumeClaim\n metadata:\n name: pvc-demo\n spec:\n accessModes:\n - ReadWriteOnce\n resources:\n requests:\n storage: 40Gi\n\n3. Verify the change by viewing PVC. To view your PVC, run the following command:\n\n kubectl get pvc \u003cvar translate=\"no\"\u003epvc-name\u003c/var\u003e -o yaml\n\n Eventually, you should see the new volume in the `status.capacity` field.\n For example: \n\n ...\n spec:\n accessModes:\n - ReadWriteOnce\n resources:\n requests:\n storage: 40Gi\n storageClassName: standard\n volumeMode: Filesystem\n volumeName: pvc-078b7484-cc8d-4077-9bcb-2c17d8d4550c\n status:\n accessModes:\n - ReadWriteOnce\n capacity:\n storage: 40Gi\n ...\n\n| **Note:** Don't edit the capacity of the PersistentVolume object directly. If you edit the capacity of a PersistentVolume, and then change the size of the corresponding PersistentVolumeClaim to the same value, volume expansion won't happen. Kubernetes will assume that the backing volume was manually resized, and that no expansion is required.\n\nIf the capacity of a PersistentVolume is modified directly, this could lead the\ncontainer file system to be incorrect. To fix these issues, see\n[troubleshoot volume expansion changes](/kubernetes-engine/docs/troubleshooting/troubleshooting-gke-storage#volume_expansion_changes_not_reflecting_in_the_container_filesystem).\n\nManaging volume expansions in StatefulSets\n------------------------------------------\n\nIf you need to increase the size of volumes used by Pods within a\n[StatefulSet](https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#creating-a-statefulset)\nin Kubernetes, you should adjust the `spec.resources.requests.storage` field\nof the PersistentVolumeClaims (PVCs) associated with the Pods. Attempting to\nmodify the `volumeClaimTemplates` field directly in the StatefulSet\nobject will cause an error.\n\nAdditionally, if you increase the replica count of the StatefulSet,\nit will still create PVCs of the original size. To permanently change the\nsize of the volumes provisioned for the Pods managed by the StatefulSet,\nyou must delete and recreate the StatefulSet object with the updated size\nthat's specified in the `volumeClaimTemplates` field.\n\nYou can perform the following steps in order to keep the original Pods up and\nrunning while adjusting the StatefulSet to provision future replicas with the\nnew volume size.\n\n1. Save the existing StatefulSet to a file:\n\n kubectl get StatefulSet \u003cvar translate=\"no\"\u003estatefulset-name\u003c/var\u003e -o yaml \u003e sts-backup.yaml\n\n2. For each PersistentVolumeClaim in the StatefulSet, open the\n `PersistentVolumeClaim` object in a text editor:\n\n kubectl edit pvc \u003cvar translate=\"no\"\u003ePVC_NAME\u003c/var\u003e\n\n3. Update the `spec.resources.requests.storage` field to the new volume size,\n like in the following example:\n\n apiVersion: v1\n kind: PersistentVolumeClaim\n metadata:\n # lines omitted for clarity\n spec:\n resources:\n requests:\n storage: 14Gi\n # lines omitted for clarity\n\n For details, see [Expanding Persistent Volumes Claims](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#expanding-persistent-volumes-claims).\n4. Save your edits and close the text editor. Wait for Kubernetes to update the\n PersistentVolumeClaim with your changes.\n\n5. Remove the StatefulSet object from the cluster while keeping the Pods\n running as standalone Pods:\n\n kubectl delete sts \u003cvar translate=\"no\"\u003estatefulset-name\u003c/var\u003e --cascade=orphan\n\n6. Edit the new volume storage size in the locally saved `sts-backup.yaml`\n file, specifically the value of `spec.volumeClaimTemplates.spec.resources.requests.storage`\n\n7. Recreate the StatefulSet back in the cluster:\n\n kubectl apply -f sts-backup.yaml\n\nWhat's next\n-----------\n\n- Learn more about [volumes](https://kubernetes.io/docs/concepts/storage/volumes/).\n- Learn more about [Resizing Persistent Volumes using Kubernetes](https://kubernetes.io/blog/2018/07/12/resizing-persistent-volumes-using-kubernetes/)."]]