All Products
Search
Document Center

Container Service for Kubernetes:Use dynamically provisioned disks for stateful applications

Last Updated:Feb 28, 2026

Container Service for Kubernetes (ACK) can automatically create and attach disks to your workloads through dynamic provisioning. Define a StorageClass and a persistent volume claim (PVC), and the system creates a persistent volume (PV) and its backing disk on demand when you deploy your application.

How it works

  1. Create a PVC that references a StorageClass.

  2. Deploy your application with a volume that references the PVC.

  3. The provisioner automatically creates a disk and binds it to the PVC as a PV.

By default, a provisioner is automatically installed in each ACK cluster.

Prerequisites

Default StorageClasses

ACK creates four StorageClasses during cluster initialization. These StorageClasses use default settings and only work for single-zone clusters. For multi-zone clusters, create a custom StorageClass.

StorageClass nameDisk typeDescription
alicloud-disk-commonBasic diskStandard baseline storage
alicloud-disk-efficiencyUltra diskBalanced performance and cost
alicloud-disk-ssdSSDHigh-performance storage
alicloud-disk-availableHigh availabilityTries to create an SSD first. If SSD resources are exhausted, creates an ultra disk instead.

Create a custom StorageClass

If the default StorageClasses do not meet your requirements (for example, your cluster spans multiple zones), create a custom StorageClass.

  1. Create a file named storageclass.yaml:

        kind: StorageClass
        apiVersion: storage.k8s.io/v1
        metadata:
          name: alicloud-disk-ssd-hangzhou-b
        provisioner: alicloud/disk
        reclaimPolicy: Retain
        parameters:
          type: cloud_ssd
          regionId: cn-hangzhou
          zoneId: cn-hangzhou-b
          fstype: "ext4"
          readonly: "false"
  2. Create the StorageClass:

        kubectl create -f storageclass.yaml

StorageClass parameters

ParameterDescription
provisionerSet to alicloud/disk. The provisioner automatically creates disks.
reclaimPolicyControls what happens to the disk when the PVC is deleted. Valid values: Delete, Retain. Default: Delete.
typeDisk type. Valid values: cloud, cloud_efficiency, cloud_ssd, available.
regionIdRegion of the disk. Must match the cluster region. Optional.
zoneIdZone of the disk. Optional. For a single-zone cluster, set this to the zone ID. For a multi-zone cluster, specify comma-separated zone IDs (for example, cn-hangzhou-a,cn-hangzhou-b,cn-hangzhou-c).
fstypeFile system type. Optional. Default: ext4.
readonlyWhether the disk is read-only. Optional. Valid values: true, false. Default: false.
encryptedWhether to encrypt the disk. Optional. Valid values: true, false. Default: false.
Note If you set reclaimPolicy to Delete, the disk is automatically deleted when you delete the PVC. The disk data cannot be recovered.

Create a PVC

  1. Create a file named pvc-ssd.yaml:

        kind: PersistentVolumeClaim
        apiVersion: v1
        metadata:
          name: disk-ssd
        spec:
          accessModes:
            - ReadWriteOnce
          storageClassName: alicloud-disk-ssd-hangzhou-b
          resources:
            requests:
              storage: 20Gi
  2. Create the PVC:

        kubectl create -f pvc-ssd.yaml

Create a Deployment

  1. Create a file named pvc-dynamic.yaml:

        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
  2. Create the Deployment:

        kubectl create -f nginx-dynamic.yaml

Verify persistent storage

After creating the Deployment, verify that the disk is mounted and that data persists across pod restarts.

Confirm the disk is mounted

  1. Find the pod name:

        kubectl get pod | grep dynamic

    Expected output:

        nginx-dynamic-5c74594ccb-zl9pf     2/2     Running     0          3m
  2. Verify the disk is mounted at /data:

        kubectl exec nginx-dynamic-5c74594ccb-zl9pf -- df | grep data

    Expected output:

        /dev/vdh        20511312    45080  20449848   1% /data
  3. List files in /data:

        kubectl exec nginx-dynamic-5c74594ccb-zl9pf -- ls /data

    Expected output:

        lost+found

Write test data and verify persistence

  1. Create a test file on the disk:

        kubectl exec nginx-dynamic-5c74594ccb-zl9pf -- touch /data/dynamic
  2. Confirm the file exists:

        kubectl exec nginx-dynamic-5c74594ccb-zl9pf -- ls /data

    Expected output:

        dynamic
        lost+found
  3. Delete the pod to trigger a replacement:

        kubectl delete pod nginx-dynamic-5c74594ccb-zl9pf

    Expected output:

        pod "nginx-dynamic-5c74594ccb-zl9pf" deleted
  4. In a separate terminal, watch the pod lifecycle:

        kubectl get pod -w -l app=nginx

    Expected output:

        NAME                               READY   STATUS    RESTARTS   AGE
        nginx-dynamic-5c74594ccb-zl9pf     2/2     Running   0          6m48s
        nginx-dynamic-5c74594ccb-zl9pf   2/2   Terminating   0     7m32s
        nginx-dynamic-5c74594ccb-45sd4   0/2   Pending   0     0s
        nginx-dynamic-5c74594ccb-45sd4   0/2   Pending   0     0s
        nginx-dynamic-5c74594ccb-45sd4   0/2   Init:0/1   0     0s
        nginx-dynamic-5c74594ccb-zl9pf   0/2   Terminating   0     7m32s
        nginx-dynamic-5c74594ccb-zl9pf   0/2   Terminating   0     7m33s
        nginx-dynamic-5c74594ccb-zl9pf   0/2   Terminating   0     7m33s
        nginx-dynamic-5c74594ccb-45sd4   0/2   PodInitializing   0     5s
        nginx-dynamic-5c74594ccb-45sd4   2/2   Running   0     22s
  5. Get the name of the new pod:

        kubectl get pod

    Expected output:

        NAME                               READY   STATUS      RESTARTS   AGE
        nginx-dynamic-5c74594ccb-45sd4     2/2     Running     0          2m
  6. Verify the test file still exists in the new pod:

        kubectl exec nginx-dynamic-5c74594ccb-45sd4 -- ls /data

    Expected output:

        dynamic
        lost+found

    The dynamic file persists after the pod is deleted and recreated. This confirms that the dynamically provisioned disk provides persistent storage.