All Products
Search
Document Center

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

Last Updated:Jun 25, 2026

When containers fail, stateful application data stored in container storage can be lost or become unreliable. Persistent storage addresses this risk. This topic explains how to use dynamically provisioned disks to implement persistent storage.

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.

Each ACK cluster includes a provisioner by default.

Prerequisites

Default StorageClasses

ACK creates four default StorageClasses at cluster initialization. They only work for single-zone clusters. For multi-zone clusters, create a custom StorageClass.

StorageClass name Disk type Description
alicloud-disk-common Basic disk Standard baseline storage
alicloud-disk-efficiency Enhanced SSD (ESSD) Balanced performance and cost
alicloud-disk-ssd SSD High-performance storage
alicloud-disk-available High availability Creates an SSD if available; falls back to ultra disk.

Create a custom StorageClass

Create a custom StorageClass if defaults do not meet your needs, for example in multi-zone clusters.

  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

Parameter Description
provisioner The disk provisioner plugin. Set to alicloud/disk.
reclaimPolicy Disk behavior on PVC deletion. Valid values: Delete, Retain. Default: Delete.
type Disk type. Valid values: cloud, cloud_efficiency, cloud_ssd, available.
regionId Region of the disk. Must match the cluster region. Optional.
zoneId Disk zone. Optional. Single-zone cluster: the zone ID. Multi-zone cluster: comma-separated IDs (for example, cn-hangzhou-a,cn-hangzhou-b,cn-hangzhou-c).
fstype File system type. Optional. Default: ext4.
readonly Whether the disk is read-only. Optional. Valid values: true, false. Default: false.
encrypted Whether 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

Confirm the disk is mounted and 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 across pod recreation, confirming the disk provides persistent storage.