How can I increase the storage size of a Persistent Volume Claim (PVC)?

You can increase the storage size of your PVC by editing it.

Be sure to edit your PVC as deleting and recreating it will result in the loss of your data.

To see a list of your PVCs, run the following command replacing <namespace> with your value:

kubectl -n <namespace> get pvc
  1. Confirm that the volume manager storageClass can support the increase on the cluster. For reference, you can use Kafka, Zookeeper, MongoDB, PostgreSQL, MinIO.

    1. Retrieve the <storageclass_name> of your PVC by running the following command line, replacing <namespace> and <pvc_name> with your values:

      kubectl -n <namespace> get pvc <pvc_name> -o jsonpath='{.spec.storageClassName}'
    2. Check if your PVC can be increased by running the following command line, replacing <storageclass_name> with your value:

      kubectl get storageclasses.storage.k8s.io <storageclass_name> -o jsonpath='{.allowVolumeExpansion}'

      If the response for allowVolumeExpansion is true, you can increase the storage of your PVC.

  2. Scale down all pods using the PVC you want to edit by running the following command line, replacing <namespace> and, depending on your PVC, either <deployment_name> or <statefulset_name> with your values:

    kubectl -n <namespace> scale deployment/<deployment_name> --replicas 0 (1)
    
    kubectl -n <namespace> scale statefulset/<statefulset_name> --replicas 0 (1)

    Where:

    1 The 0 after --replicas represents the action of scaling down a pod.

    Once you have confirmed that your storageClass supports the storage increase and you have scaled down your pod, you are ready to increase the storage size.

  3. Edit your PVC by running the following command line, replacing <namespace> and <pvc_name> with your values:

    kubectl -n <namespace> edit pvc <pvc_name>
  4. OPTIONAL: To get more information about your PVC, including the storage capacity, run the following command line replacing <namespace> and <pvc_name> with your values:

    kubectl -n <namespace> describe pvc <pvc_name>
  5. Locate the spec section of the response:

    spec:
      accessModes:
      - ReadWriteOnce
      dataSource: null
      resources:
        requests:
          storage: 32Gi
      storageClassName: common-storageclass
      volumeName: pvc-jhz434ui92
  6. Change the spec.resources.requests.storage value with your new increased storage amount. Note that you can only increase storage. Decreasing storage is not supported.

    Once you have saved your changes, the output of the command should look like the following:

    persistentvolumeclaim/<pvc_name> edited

    Where:

    • <pvc_name> is the name of your PVC.

  7. Run the following command line, replacing <namespace> and <pvc_name> with your values, to see the state of your PVC:

    kubectl -n <namespace> describe pvc <pvc_name>

    The output of the command should look like the following:

    Conditions:
    Type                      Status  LastProbeTime                     LastTransitionTime                Reason  Message
    ----                      ------  -----------------                 ------------------                ------  -------
    FileSystemResizePending   True    Mon, 01 Jan 0001 00:00:00 +0000   Fri, 13 Mar 2020 15:03:55 +0100           Waiting for user to (re-)start a pod to finish file system resize of volume on node.
  8. Locate your <replicas_default> value by running a describe command for either a deployment or a statefulset, replacing <namespace> and either <deployment_name> or <statefulset_name> with your values:

    kubectl -n <namespace> describe deployment <deployment_name>
    
    kubectl -n <namespace> describe statefulset <statefulset_name>
  9. Run the same command used to scale down your pods, replacing the 0 with your <replicas_default> value:

    Be sure to also replace <namespace> and either <deployment_name> or <statefulset_name> with your values.
    kubectl -n <namespace> scale deployment/<deployment_name> --replicas <replicas_default>
    
    kubectl -n <namespace> scale statefulset/<statefulset_name> --replicas <replicas_default>

After scaling your pod, it will take a few minutes before the pod, with its new storage volume, is usable.