This topic describes how to extend a disk that is used in a stateful service.
Background
When you use a cloud disk to create a stateful service, you may encounter the following problems: when you first request a cloud disk, you cannot accurately estimate the storage space that may be used by the service. The size of the requested disk may be insufficient after the service has been running for a period of time.
You can extend the disk to meet the actual needs.
Prerequisites
- You have created a Kubernetes cluster. For more information, see Create a dedicated Kubernetes cluster.
- You can use kubectl to connect to the Kubernetes cluster. For more information, see Use kubectl to connect to an ACK cluster.
- You have created a PVC and bound it to the automatically created disk. For more information, see Use dynamic disks to create PVs for stateful services and Use dynamic disks to create PVs for stateful services.
- You have manually created a disk snapshot.
Create an application
- Create an nginx-dynamic.yaml file with the following content. For more information, see Use dynamic disks to create PVs for stateful services.
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-dynamic labels: app: nginx spec: selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx volumeMounts: - name: disk-pvc mountPath: "/data" volumes: - name: disk-pvc persistentVolumeClaim: claimName: disk-ssd
- Run the following command to create a Deployment.
$ kubectl create -f nginx-dynamic.yaml deployment.apps/nginx-dynamic created
- Run the following command to view the Pod that runs the application.
$ kubectl get pod NAME READY STATUS RESTARTS AGE nginx-dynamic-5b4bdb64c4-f7jwv 1/1 Running 0 1m
- Run the following command to view the disk that the application is using.
$ kubectl get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE d-bp18weq7be93l9iaobe6 20Gi RWO Retain Bound default/disk-ssd alicloud-disk-ssd-hangzhou-g 2m
- Run the following command to check whether a new disk is mounted to the /data path:
$ kubectl exec nginx-dynamic-5b4bdb64c4-f7jwv df | grep data /dev/vdc 20511312 45080 20449848 1% /data
- Run the following command to view the files under the /data path:
$ kubectl exec nginx-dynamic-5b4bdb64c4-f7jwv ls /data lost+found
- Run the following command to create a file named disk under the /data path:
$ kubectl exec nginx-dynamic-5b4bdb64c4-f7jwv touch /data/disk
- Run the following command to view the files under the /data path:
$ kubectl exec nginx-dynamic-5b4bdb64c4-f7jwv ls /data disk lost+found
Unmount the disk
Run the following command to delete the application and unmount the disk.
Result
$ kubectl delete deploy nginx-dynamic
deployment.extensions "nginx-dynamic" deleted
Log on to the ECS console. In the left-side navigation pane, choose disk ID to find the target disk. The disk Status is Unattached, indicating that the disk is unmounted.
. Search by 
Extend the disk
- Log on to the ECS console.
- In the left-side navigation pane, choose Disks page. to go to the
- Search by disk ID to find the target disk and choose in the Actions column.
Note For more information, see Resize partitions and file systems of Linux data disks.
- Extend a disk from 20 GB to 30 GB.
On the Disks page, search by disk ID to find the target disk. The Disk Category (All) shows that the disk size is 30 GB.

Extend the file system
- Log on to the Container Service console.
- In the left-side navigation pane, choose Nodes page. to go to the
- Select the target cluster and mount the extended disk to a worker node. Click the ID of the worker node.
- In the left-side navigation pane, click Disks. On the Disks page, click Create Disk in the upper-right corner. For more information, see Attach a data disk.
- On the Mount Disk page, select the target disk.
- On the Disks page, choose the target disk and choose in the Actions column to view Device Name.
- Log on to the worker node where the target disk is mounted.
- Run the following command to view the file system.
$ e2fsck -f /dev/vdc
- Run the following command to resize the file system.
$ resize2fs /dev/vdc
Create an application
- Create an nginx-dynamic.yaml file with the following content.
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-dynamic labels: app: nginx spec: selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx volumeMounts: - name: disk-pvc mountPath: "/data" volumes: - name: disk-pvc persistentVolumeClaim: claimName: disk-ssd
- Run the following command to create a Deployment.
$ kubectl create -f nginx-dynamic.yaml deployment.apps/nginx-dynamic created
- Run the following command to view the Pod that runs the Deployment.
$ kubectl get pod | grep static nginx-dynamic-5b4bdb64c4-gxqs5 0/1 ContainerCreating 0 15s
- Run the following command to verify that the disk is extended to the previously specified
size.
$ kubectl exec nginx-dynamic-5b4bdb64c4-gxqs5 df | grep data /dev/vdc 30832548 45036 30771128 1% /data
- Run the following command to view the content under the /data path. The content is the same before and after disk extension.
$ kubectl exec nginx-dynamic-5b4bdb64c4-gxqs5 ls /data disk lost+found