Resize a disk volume (for clusters earlier than version 1.16)

更新时间:
复制 MD 格式

If your cluster runs a Kubernetes version earlier than 1.16 or uses basic disks, you cannot expand a disk volume by updating its persistent volume claim (PVC). Instead, you must directly expand the underlying disk and its file system.

Scope

This topic describes how to expand a disk volume by manually expanding the underlying disk without modifying the PVC. You can use this method if your cluster runs a Kubernetes version earlier than 1.16 or does not meet the requirements for online expansion of a disk volume.

Important

With this method, you expand the disk in the ECS console. This does not affect resources within the cluster, so the capacity of the persistent volume claim (PVC) and persistent volume (PV) objects remains unchanged. To ensure that the PV and PVC capacities displayed in the cluster are consistent with the actual capacity, we recommend that you use online expansion of a disk volume.

Choose a method based on your business needs.

  • Online expansion: The application continues to run. However, if the I/O traffic is high during the file system expansion, I/O errors may occur.

  • Offline expansion: This process pauses the application and its disk I/O. As a result, the file system expansion is safer for your data, but the application is paused for a period of time.

Important

Basic disks do not support online expansion. You must use offline expansion.

The following sections use a sample application with a statically provisioned disk volume to demonstrate how to expand the disk volume.

Online expansion

Expand the disk in the ECS console while the application remains running.

Step 1: View disk information

  1. Connect to your cluster. For more information, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster or Use kubectl to connect to a Kubernetes cluster from Workbench or CloudShell.

  2. View the pod that mounts the disk and confirm that the pod is in the Running state.

    kubectl get pod 

    Example output:

    NAME          READY   STATUS    RESTARTS   AGE
    disk-test-0   1/1     Running   0          38s
  3. View the PVC to get the disk ID.

    kubectl get pvc

    The following output shows that the PV bound to the PVC is d-uf628m33r5rsbi****** (the disk ID) and the capacity is 20 GiB.

    NAME       STATUS   VOLUME                   CAPACITY   ACCESS MODES   STORAGECLASS   VOLUMEATTRIBUTESCLASS   AGE
    disk-pvc   Bound    d-uf628m33r5rsbi******   20Gi       RWO            disk           <unset>                 64s

Step 2: Expand disk and file system

  1. Log in to the ECS console.

  2. In the left-side navigation pane, choose Storage & Snapshots > Block Storage.

  3. In the upper-left corner of the page, select a region and resource group.地域

  4. Find the disk by its ID, select the disk, and then click Scale-out at the bottom of the page.

    For more information about how to expand a disk, see Expand a disk (Linux).
  5. In the wizard that appears, follow the on-screen instructions to complete the expansion.

    • On the Determine Disk and Read Notes page, confirm the disk information, read the notes, and then click I Understand Risks and Have Backed Up Data, Proceed.

    • On the Configure Resizing Method and New Size page, set the parameters for expansion and click Scale-out.

      Parameter

      Description

      Example

      New disk size

      Specify the capacity to which you want to expand the disk. The new capacity cannot be smaller than the current capacity.

      30 GiB

      Resizing method

      Select Online Resizing. The new capacity takes effect immediately without a restart.

      Online Resizing

    • On the Confirm Resizing Results page, confirm that the disk is expanded and then click Next Step: Extend Partitions and File Systems.

      Note

      After you expand the disk, you must also expand its file system. Otherwise, the storage space in the container remains the original size.

    • On the Extend the partitions and file systems of disks page, select Use Cloud Assistant, select Authorize Cloud Assistant to Perform This Operation, and then click Authorization.

      After the operation is complete, confirm that both the disk and its file system are expanded.

      After the expansion is successful, the disk check page shows a green check mark and the message The disk check is complete. The disk is ready for use. In the Disk information in the operating system section, verify that the Disk capacity (OS) value matches the Capacity value. In the partition details, check that the size of the partition (for example, /dev/vdb) equals the total disk capacity. This confirms that both the partition and file system are successfully expanded.

Offline expansion

Pause the application by setting the number of replicas to 0, expand the disk, and then restart the application.

Step 1: View disk information and pause the application

  1. Connect to your cluster. For more information, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster or Use kubectl to connect to a Kubernetes cluster from Workbench or CloudShell.

  2. View the pod that mounts the disk and confirm that the pod is in the Running state.

    kubectl get pod 

    Example output:

    NAME          READY   STATUS    RESTARTS   AGE
    disk-test-0   1/1     Running   0          38s
  3. View the PVC to get the disk ID.

    kubectl get pvc

    The following output shows that the PV bound to the PVC is d-uf628m33r5rsbi****** (the disk ID) and the capacity is 20 GiB.

    NAME       STATUS   VOLUME                   CAPACITY   ACCESS MODES   STORAGECLASS   VOLUMEATTRIBUTESCLASS   AGE
    disk-pvc   Bound    d-uf628m33r5rsbi******   20Gi       RWO            disk           <unset>                 64s
  4. Scale down the application to 0 replicas to pause the application.

    kubectl scale sts disk-test --replicas=0

    Expected output:

    statefulset.apps/disk-test scaled

Step 2: Expand the disk

  1. Log in to the ECS console.

  2. In the left-side navigation pane, choose Storage & Snapshots > Block Storage.

  3. In the upper-left corner of the page, select a region and resource group.地域

  4. Find the disk by its ID, select the disk, and then click Scale-out at the bottom of the page.

  5. In the wizard that appears, follow the on-screen instructions to complete the expansion.

    • On the Determine Disk and Read Notes page, confirm the disk information, read the notes, and then click I Understand Risks and Have Backed Up Data, Proceed.

    • On the Configure Resizing Method and New Size page, set the parameters for expansion and click Scale-out.

      Parameter

      Description

      Example

      New disk size

      Specify the capacity to which you want to expand the disk. The new capacity cannot be smaller than the current capacity.

      30 GiB

      Resizing method

      After you pause the application, the disk is in the Unattached state. In this state, Offline Resizing is the only available option.

      Offline Resizing

    • On the Confirm Resizing Results page, confirm that the disk is expanded and then click Next Step: Extend Partitions and File Systems.

    • On the Extend the partitions and file systems of disks page, select Use Documentation and view the documentation in the Extend the partitions and file systems of disks on a Linux instance section.

      Note
      • After you expand the disk, you must also expand its file system. Otherwise, the storage space in the container remains the original size.

      • Because the disk is in the Unattached state, you cannot use Cloud Assistant. You must manually expand the file system.

Step 3: Expand the file system

The following steps apply to unpartitioned disks.

Important

We recommend not using partitioned disks in Kubernetes.

  1. Attach the disk to an ECS instance.

    1. On the EBS page in the ECS console, find the target disk and click Attach in the Actions column.

    2. In the Attach to Instance wizard, select the target ECS instance and click Next.

      Important

      Do not select any options that automatically release the disk.

    3. In the Partition Disk and Create and Mount File Systems wizard, click Configure Later in the Initialization Method section.

    4. Confirm that the status of the disk changes to In Use.

  2. Connect to the ECS instance. For more information, see Connection methods.

  3. Obtain the device name of the disk.

    Replace <serial> with your disk's serial number.

    The disk serial number is part of the disk ID, which has the format d-{disk serial number}. For more information, see View the serial number of a block storage device.

    Important

    Disks created before June 10, 2020, do not have serial numbers. For these disks, you cannot use the realpath command to find the device name. Instead, run the ls /dev/vd* command before and after attaching the disk, and then compare the outputs to identify the new device name.

    realpath /dev/disk/by-id/virtio-<serial>

    The following sample output indicates that the device name of the disk is /dev/vdb.

    /dev/vdb
  4. Expand the file system.

    Replace /dev/vdb with the actual device name of your disk.

    resize2fs /dev/vdb

    If you see the following error, run e2fsck -f /dev/vdb as prompted, and then run resize2fs /dev/vdb again to expand the file system.

    resize2fs 1.46.0 (29-Jan-2020)
    Please run 'e2fsck -f /dev/vdb' first.

    After the file system is successfully expanded, the following output is returned:

    resize2fs 1.46.0 (29-Jan-2020)
    Resizing the filesystem on /dev/vdb to 7864320 (4k) blocks.
    The filesystem on /dev/vdb is now 7864320 (4k) blocks long.
  5. Confirm that the file system is expanded.

    1. Create a temporary directory /mnt/disk/ and mount the disk to it.

      mkdir /mnt/disk
      mount /dev/vdb /mnt/disk/
    2. Check the file system size.

      df /mnt/disk/

      The following sample output shows that the capacity of /dev/vdb is expanded to 30 GiB.

      Filesystem     1K-blocks  Used Available Use% Mounted on
      /dev/vdb        30787536    24  30771128   1% /mnt/disk
    3. Unmount the disk from the temporary directory.

      umount /mnt/disk
  6. Detach the data disk from the ECS instance. For more information, see Detach a data disk.

Step 4: Restart the application

  1. Scale up the application to 1 replica to restart the application.

    kubectl scale sts disk-test --replicas=1

    Expected output:

    statefulset.apps/disk-test scaled
  2. Confirm that the pod is restored.

    kubectl get pod

    Expected output:

    NAME          READY   STATUS    RESTARTS   AGE
    disk-test-0   1/1     Running   0          5s
  3. Check the file system size.

    kubectl exec -it disk-test-0 -- df /data

    The following sample output shows that the mounted file system was successfully expanded.

    Filesystem     1K-blocks  Used Available Use% Mounted on
    /dev/vdb        30787536    24  30771128   1% /data