All Products
Search
Document Center

Container Compute Service:Use a dynamic disk as a persistent volume

Last Updated:Jan 22, 2026

For applications that handle non-shared data and require low latency and high I/O performance, you can use a disk as a Persistent Volume (PV). This topic shows how to mount a dynamic disk volume to an application and verify its data persistence.

Background information

Disks are a block storage service for block-level data. They use a distributed, multi-replica architecture to deliver low latency, high performance, durability, and reliability. This makes them ideal for applications that handle non-shared data and require high I/O performance and low latency. For more information, see Storage overview.

Note

Alibaba Cloud Container Compute Service (ACS) supports only dynamic mounting of disk volumes. Statically mounting disk volumes is not supported.

Prerequisites

The managed-csiprovisioner component is installed in the ACS cluster.

Note

Go to the ACS cluster management page in the ACS console. In the left-side navigation pane of the cluster management page, choose Operations > Add-ons. On the Storage tab, you can check whether managed-csiprovisioner is installed.

Limitations

  • Disks provide non-shared storage. A disk volume can only be mounted to a single Pod.

  • A disk can only be mounted to a Pod within the same Availability Zone; cross-zone mounting is not supported.

Usage notes

  • We recommend using a StatefulSet or mounting a disk to a standalone Pod. Using a Deployment is not advised, for the following reason:

    • To mount a disk to a Deployment, you must set replicas: 1, because a disk can only attach to one Pod. This prevents per-Pod volumes, offers no guaranteed mount/unmount order, and—due to the Deployment's update strategy—can cause significant mount delays during restarts.

  • When you use a dynamic disk volume, the automatically created disk uses the pay-as-you-go billing method.

  • If you configure securityContext.fsGroup in your application's YAML file when using a dynamic disk volume, ACS will run chmod and chown operations after the mount is complete. This increases the mount time.

    Note

    When securityContext.fsGroup is configured, the owner of the files in the volume is automatically adjusted during the mount process. Depending on the number of files, this can significantly increase startup time. Set fsGroupChangePolicy to OnRootMismatch to change file ownership only when the container starts for the first time.

    For subsequent Pod upgrades or rebuilds, the mount time will return to normal. If this approach is unsuitable, consider using an init container to implement your own permission-setting logic.

Mount a disk volume

kubectl

By default, ACS provides a StorageClass named alicloud-disk-topology-alltype. This StorageClass attempts to create a Persistent Volume (PV) by trying the following disk types in order: cloud_essd (ESSD), cloud_ssd (standard SSD), and cloud_efficiency (ultra disk). If the default StorageClass does not meet your requirements, follow these steps to create a new one.

  1. Connect to your ACS cluster. For more information, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster and Use kubectl on Cloud Shell to manage ACS clusters.

  2. Modify and save the following YAML as disk-sc.yaml based on the parameters described in the table below.

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: alicloud-disk-essd
    provisioner: diskplugin.csi.alibabacloud.com
    parameters:
      type: cloud_essd
      fstype: ext4
      performanceLevel: PL1
    reclaimPolicy: Delete
    volumeBindingMode: WaitForFirstConsumer
    allowVolumeExpansion: true

    The following table describes the parameters.

    Parameter

    Description

    parameters.type

    The type of disk. Valid values:

    • cloud_essd_entry: ESSD Entry disk

    • cloud_auto: ESSD AutoPL disk

    • cloud_essd (default): ESSD

    • cloud_ssd: standard SSD

    • cloud_efficiency: ultra disk

      You can combine these parameters, for example, type: cloud_efficiency, cloud_ssd, cloud_essd. The system will try to create a disk of each specified type in order until one is created.

    Note

    Choose a disk type based on your billing and performance needs. For more information, see Prices of block storage devices and Block storage performance.

    parameters.fstype

    The file system type for the disk. The default is ext4. Supported types are ext3, ext4, and xfs.

    parameters.performanceLevel

    The performance level of the ESSD. The default is PL1. Supported levels are PL0, PL1, PL2, and PL3. For more information, see ESSDs.

    provisioner

    The driver type. Set this to diskplugin.csi.alibabacloud.com to use the Alibaba Cloud disk CSI plug-in.

    reclaimPolicy

    The reclaim policy for the disk. Only Delete is supported, meaning that when you delete the PVC, the system also deletes the PV and its underlying disk.

    volumeBindingMode

    The volume binding mode. If you are using a multi-zone cluster, we recommend setting this to WaitForFirstConsumer.

    • WaitForFirstConsumer: Delays volume binding. The Pod is scheduled first, and then the disk is created based on the Pod's Availability Zone.

    • Immediate: The disk is created before the Pod.

    Important

    If you use ACS computing power in an ACK cluster and the ACS Pod needs to mount a disk, use nodeSelector or ResourcePolicy to schedule the Pod to a virtual node. If you schedule the Pod by adding the Pod label alibabacloud.com/acs: "true", StorageClasses with volumeBindingMode: WaitForFirstConsumer are not supported.

    allowVolumeExpansion

    Specifies whether to automatically expand the disk.

  3. Create a StorageClass.

    kubectl create -f disk-sc.yaml
  4. Check the StorageClass.

    kubectl get sc

    Expected output:

    NAME                             PROVISIONER                       RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
    alicloud-disk-essd               diskplugin.csi.alibabacloud.com   Delete          WaitForFirstConsumer   true                   78s
    alicloud-disk-topology-alltype   diskplugin.csi.alibabacloud.com   Delete          WaitForFirstConsumer   true                   23d
    ......
  5. Save the following YAML as disk-pvc.yaml.

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: disk-pvc
    spec:
      accessModes:
      - ReadWriteOncePod
      volumeMode: Filesystem
      resources:
        requests:
          storage: 20Gi
      storageClassName: alicloud-disk-essd

    The following table describes the parameters.

    Parameter

    Description

    accessModes

    The access mode. Only ReadWriteOncePod is currently supported.

    volumeMode

    The volume mode. Valid values: Filesystem (default) or Block.

    storage

    The amount of storage to allocate to the Pod, which is the size of the disk to be created.

    storageClassName

    The name of the StorageClass to bind.

  6. Create the PVC.

    kubectl create -f disk-pvc.yaml
  7. Check the PVC.

    kubectl get pvc

    The expected output shows that the PVC has not yet been bound to a PV because volumeBindingMode is set to WaitForFirstConsumer.

    NAME       STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS         VOLUMEATTRIBUTESCLASS   AGE
    disk-pvc   Pending                                      alicloud-disk-essd   <unset>                 7s
  8. Save the following YAML as disk-test.yaml.

    The following YAML defines a StatefulSet with one Pod. The Pod requests storage resources through a PVC named disk-pvc and mounts the volume to the /data path.

    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: disk-test
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: registry.cn-hangzhou.aliyuncs.com/acs-sample/nginx:latest
            ports:
            - containerPort: 80
            volumeMounts:
            - name: pvc-disk
              mountPath: /data
          volumes:
            - name: pvc-disk
              persistentVolumeClaim:
                claimName: disk-pvc
  9. Create the StatefulSet and mount the disk.

    kubectl create -f disk-test.yaml
    Important

    When you create the StatefulSet, the system automatically provisions a pay-as-you-go disk and a corresponding PV based on the PVC and StorageClass configurations.

  10. Check the deployment status of the Pod in the StatefulSet.

    kubectl get pod | grep disk-test

    The output shows one Pod, as expected, because replicas is set to 1 in the StatefulSet.

    disk-test-0   1/1     Running   0          52s
  11. Check the PVC.

    kubectl get pvc

    The expected output shows that the PVC is now bound to the automatically created PV of the disk type.

    NAME       STATUS   VOLUME                   CAPACITY   ACCESS MODES   STORAGECLASS         VOLUMEATTRIBUTESCLASS   AGE
    disk-pvc   Bound    d-uf698s3h14isyj6b****   20Gi       RWOP           alicloud-disk-essd   <unset>                 111s
  12. Check the mount path to confirm that the disk is mounted.

    kubectl exec disk-test-0 -- df | grep data

    Expected output:

    /dev/vdb        20466256      24  20449848   1% /data

Console

By default, ACS provides a StorageClass named alicloud-disk-topology-alltype. This StorageClass attempts to create a Persistent Volume (PV) by trying the following disk types in order: cloud_essd (ESSD), cloud_ssd (standard SSD), and cloud_efficiency (ultra disk). If the default StorageClass does not meet your requirements, follow these steps to create a new one.

  1. Log on to the ACS console.

  2. On the Clusters, click the name of the cluster to go to the cluster management page.

  3. In the left-side navigation pane of the cluster management page, choose Volumes > StorageClasses.

  4. Create a StorageClass.

    1. On the StorageClasses page, click Create.

    2. In the dialog box that appears, configure the parameters and then click Create.

      Parameter

      Description

      Example

      Name

      The name of the StorageClass. Follow the format requirements on the screen.

      alicloud-disk-essd

      PV Type

      Select Cloud Disk.

      Cloud Disk

      Parameter

      The default parameter is type, which specifies the disk type. Valid values are:

      • cloud_essd_entry: ESSD Entry disk

      • cloud_auto: ESSD AutoPL disk

      • cloud_essd (default): ESSD

      • cloud_ssd: standard SSD

      • cloud_efficiency: ultra disk

        You can combine these parameters, for example, type: cloud_efficiency, cloud_ssd, cloud_essd. The system will try to create a disk of each specified type in order until one is created.

      Note

      Choose a disk type based on your billing and performance needs. For more information, see Prices of block storage devices and Block storage performance.

      You can add the following parameters:

      • fstype

        The file system type for the disk. The default is ext4. Supported types are ext3, ext4, and xfs.

      • performanceLevel

        The performance level of the ESSD. The default is PL1. Supported levels are PL0, PL1, PL2, and PL3. For more information, see ESSDs.

      type:cloud_essd

      Reclaim Policy

      The reclaim policy for the disk. Only Delete is supported, meaning that when you delete the PVC, the system also deletes the PV and its underlying disk.

      Delete

      Binding Mode

      The volume binding mode. If you are using a multi-zone cluster, we recommend setting this to WaitForFirstConsumer.

      • Delays volume binding. The Pod is scheduled first, and then the disk is created based on the Pod's Availability Zone.

      • Immediate: The disk is created before the Pod.

      Important

      If you use ACS computing power in an ACK cluster and the ACS Pod needs to mount a disk, use nodeSelector or ResourcePolicy to schedule the Pod to a virtual node. If you schedule the Pod by adding the Pod label alibabacloud.com/acs: "true", StorageClasses with volumeBindingMode: WaitForFirstConsumer are not supported.

      WaitForFirstConsumer

  5. In the left-side navigation pane of the cluster management page, choose Volumes > Persistent Volume Claims.

  6. On the Persistent Volume Claims page, click Create.

  7. In the dialog box that appears, configure the parameters and then click Create.

    Parameter

    Description

    Example

    PVC Type

    Select Cloud Disk.

    Cloud Disk

    Name

    The name of the PVC. Follow the format requirements on the screen.

    disk-pvc

    Allocation Mode

    The default selection is Use StorageClass.

    Use StorageClass

    Existing Storage Class

    Select the StorageClass to bind.

    alicloud-disk-essd

    Capacity

    The amount of storage to allocate to the Pod, which is the size of the disk to be created.

    20Gi

    Access Mode

    Only ReadWriteOncePod is supported, which means the volume can be mounted as read-write by a single Pod.

    ReadWriteOncePod

    After the PVC is created, you can see it on the Persistent Volume Claims page. Because the binding mode in the StorageClass is WaitForFirstConsumer, the PVC is not yet bound to a PV and its status is Pending.

  8. In the left-side navigation pane of the cluster management page, choose Workloads > StatefulSets.

  9. On the StatefulSets page, click Create from Image.

  10. Configure the parameters for the StatefulSet, then click Create.

    Configure the following parameters and keep the default values for the others. For more information, see Use a StatefulSet to create a stateful application.

    Configuration page

    Parameter

    Description

    Example

    Basic Information

    Name

    The name of the StatefulSet. Follow the format requirements on the screen.

    disk-test

    Replicas

    The number of replicas for the StatefulSet.

    1

    Container

    Image Name

    The address of the image to use for the application deployment.

    registry.cn-hangzhou.aliyuncs.com/acs-sample/nginx:latest

    Required Resources

    The vCPU and memory resources to request.

    0.25 vCPU, 0.5 GiB

    Volume

    Click Add PVC and configure the parameters.

    • Mount Source: Select the PVC you created earlier.

    • Container Path: Enter the path in the container where the disk should be mounted.

    • Mount Source: disk-pvc.

    • Container Path: /data.

  11. Check the application deployment status.

    1. On the StatefulSets page, click the name of the application.

    2. On the Pods tab, confirm that the Pod is running properly (its status is Running).

  12. Check the PV and PVC.

    • On the Persistent Volumes page, you can see that a PV has been automatically created. The name of the PV corresponds to the disk ID.

    • On the Persistent Volume Claims page, you can see that the PVC is now bound to the PV, and its status is Bound.

Verify disk data persistence

The StatefulSet from the previous section contains one Pod with a mounted disk. When this Pod is deleted, a new one is automatically created and re-mounts the same disk, preserving the data. To verify the disk's data persistence, follow these steps.

  1. Check the mount path to view the data on the disk.

    kubectl exec disk-test-0 -- ls /data

    Expected output:

    lost+found
  2. Write a file to the disk.

    kubectl exec disk-test-0 -- touch /data/test
  3. Delete the Pod.

    kubectl delete pod disk-test-0
    Note

    After you delete a Pod in a StatefulSet, the system automatically creates a new one.

  4. Check the newly created Pod.

    kubectl get pod

    The expected output shows that the new Pod has the same name as the old one, which is a feature of StatefulSets.

    NAME          READY   STATUS    RESTARTS   AGE
    disk-test-0   1/1     Running   0          27s
  5. Confirm that the new Pod has re-mounted the disk and that the data persists.

    kubectl exec disk-test-0 -- ls /data

    The expected output shows that the test file you wrote earlier is still on the disk.

    lost+found  test