In Tanzu Kubernetes clusters, you can expand any new or existing persistent block volume when it is offline, or not attached to a node.

By default, all storage classes that appear in the vSphere with Tanzu environment have allowVolumeExpansion set to true. This parameter makes it possible to modify the size of a volume.

Procedure

  1. Create a persistent volume claim (PVC) with available default storage class.
    1. Define a PVC using the following YAML manifest as an example.
      In the example, the size of the requested storage is 1 Gi.
      apiVersion: v1
      kind: PersistentVolumeClaim
      metadata:
        name: example-block-pvc
      spec:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 1Gi
        storageClassName: example-block-sc
    2. Apply the PVC to the Kubernetes cluster.
      kubectl apply -f example-block-pvc.yaml 
  2. Patch the PVC to increase its size.
    For example, increase the size to 2 Gi.
    Note: Before changing the size, make sure that the PVC is bound and is not attached to a pod. Only offline volume expansion is supported.
    kubectl patch pvc example-block-pvc -p '{"spec": {"resources": {"requests": {"storage": "2Gi"}}}}'
    This action triggers an expansion in the volume associated with the PVC.
  3. Verify that the size of the volume has increased.
    kubectl get pv
    NAME                                       CAPACITY ACCESS MODES RECLAIM POLICY STATUS   CLAIM                       STORAGECLASS           REASON AGE
    pvc-9e9a325d-ee1c-11e9-a223-005056ad1fc1   2Gi           RWO         Delete     Bound    default/example-block-pvc   example-block-sc              6m44s
    Note: The size of the PVC remains unchanged until the PVC is used by a pod.
    The following example shows that the PVC size hasn't changed. If you describe the PVC, you can see the FilesystemResizePending condition applied on the PVC.
    kubectl get pvc
    NAME                STATUS VOLUME                                     CAPACITY ACCESS MODES   STORAGECLASS       AGE
    example-block-pvc   Bound  pvc-9e9a325d-ee1c-11e9-a223-005056ad1fc1   1Gi           RWO       example-block-sc   6m57s
  4. Create a pod to use the PVC.
    When the PVC is used by the pod, the filesystem is expanded.
  5. Verify that the size of the PVC has been modified.
    kubectl get pvc
    NAME                STATUS VOLUME                                    CAPACITY ACCESS MODES STORAGECLASS     AGE
    example-block-pvc   Bound  pvc-24114458-9753-428e-9c90-9f568cb25788   2Gi         RWO      example-block-sc 2m12s
    The FilesystemResizePending condition has been removed from the PVC. Volume expansion is complete.