Using volume expansion

In Google Kubernetes Engine (GKE), you can use the Kubernetes volume expansion feature to easily 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 greater.
    • Check your storage vendor's documentation to verify your CSI driver supports volume expansion (the Compute Engine persistent disk CSI Driver does).
  • 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:

  1. 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
    
  2. Request a change in volume capacity by editing your PersistentVolumeClaim's spec.resources.requests.storage field. 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
    
  3. 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
    ...
    

What's next