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.
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.
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
-
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.
-
View the pod that mounts the disk and confirm that the pod is in the Running state.
kubectl get podExample output:
NAME READY STATUS RESTARTS AGE disk-test-0 1/1 Running 0 38s -
View the PVC to get the disk ID.
kubectl get pvcThe 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
Log in to the ECS console.
In the left-side navigation pane, choose .
In the upper-left corner of the page, select a region and resource group.
-
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).
-
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.
NoteAfter 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
-
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.
-
View the pod that mounts the disk and confirm that the pod is in the Running state.
kubectl get podExample output:
NAME READY STATUS RESTARTS AGE disk-test-0 1/1 Running 0 38s -
View the PVC to get the disk ID.
kubectl get pvcThe 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 -
Scale down the application to 0 replicas to pause the application.
kubectl scale sts disk-test --replicas=0Expected output:
statefulset.apps/disk-test scaled
Step 2: Expand the disk
Log in to the ECS console.
In the left-side navigation pane, choose .
In the upper-left corner of the page, select a region and resource group.
-
Find the disk by its ID, select the disk, and then click Scale-out at the bottom of the page.
-
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.
We recommend not using partitioned disks in Kubernetes.
-
If a PV uses an unpartitioned disk, do not partition it manually. Otherwise, you may damage the file system and lose data.
-
If a PV uses a partitioned disk, you must expand the partition device before you expand the file system. For more information, see Extend partitions and file systems of a disk on a Linux instance or Extend partitions and file systems of a disk on a Windows instance.
-
Attach the disk to an ECS instance.
-
On the EBS page in the ECS console, find the target disk and click Attach in the Actions column.
-
In the Attach to Instance wizard, select the target ECS instance and click Next.
ImportantDo not select any options that automatically release the disk.
-
In the Partition Disk and Create and Mount File Systems wizard, click Configure Later in the Initialization Method section.
-
Confirm that the status of the disk changes to In Use.
-
-
Connect to the ECS instance. For more information, see Connection methods.
-
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.
ImportantDisks 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 -
Expand the file system.
Replace /dev/vdb with the actual device name of your disk.
resize2fs /dev/vdbIf you see the following error, run
e2fsck -f /dev/vdbas prompted, and then runresize2fs /dev/vdbagain 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. -
Confirm that the file system is expanded.
-
Create a temporary directory
/mnt/disk/and mount the disk to it.mkdir /mnt/disk mount /dev/vdb /mnt/disk/ -
Check the file system size.
df /mnt/disk/The following sample output shows that the capacity of
/dev/vdbis expanded to 30 GiB.Filesystem 1K-blocks Used Available Use% Mounted on /dev/vdb 30787536 24 30771128 1% /mnt/disk -
Unmount the disk from the temporary directory.
umount /mnt/disk
-
-
Detach the data disk from the ECS instance. For more information, see Detach a data disk.
Step 4: Restart the application
-
Scale up the application to 1 replica to restart the application.
kubectl scale sts disk-test --replicas=1Expected output:
statefulset.apps/disk-test scaled -
Confirm that the pod is restored.
kubectl get podExpected output:
NAME READY STATUS RESTARTS AGE disk-test-0 1/1 Running 0 5s -
Check the file system size.
kubectl exec -it disk-test-0 -- df /dataThe 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