Stateful applications on Kubernetes need storage that persists beyond the pod lifecycle. This topic walks you through the end-to-end workflow for dynamically provisioning a cloud disk volume in the Container Service for Kubernetes (ACK) console: creating a StorageClass, creating a persistent volume claim (PVC), and mounting the volume in a StatefulSet workload.
Prerequisites
Before you begin, ensure that you have:
An ACK cluster. For setup instructions, see Create an ACK managed cluster
Step 1: Create a StorageClass
A StorageClass defines how ACK provisions cloud disk volumes on demand. If your cluster already has a suitable StorageClass, skip this step and proceed to Step 2: Create a PVC.
Log on to the ACK console and click ACK consoleACK consoleACK consoleClusters in the left-side navigation pane.
Click the name of your cluster. In the left-side pane, choose Volumes > StorageClasses.
On the StorageClasses page, click Create. In the Create dialog box, configure the following parameters.
Parameter Description Name The name of the StorageClass. PV Type Set to Cloud Disk. Volume Plug-in The storage plugin. This example uses Flexvolume. Parameter Key-value pairs passed to the provisioner. See StorageClass parameters below. Reclaim Policy The policy applied to the cloud disk when the PVC is deleted. Default: Delete. Set to Retain to preserve data if the PVC is accidentally deleted. Binding Mode Controls when volume binding occurs. Immediate (default): binds as soon as the PVC is created. WaitForFirstConsumer: delays binding until a pod using the PVC is scheduled. Mount Options Additional options passed to the mount command. Multiple options are supported. Click Create. The StorageClass appears in the StorageClasses list.
StorageClass parameters
The Parameter field accepts key-value pairs. The following parameters are supported for cloud disk volumes:
| Parameter | Valid values | Description |
|---|---|---|
type | cloud_efficiency, cloud_ssd, cloud_essd, available | The cloud disk type. If set to available, ACK tries disk types in this order: enhanced SSD (ESSD), standard SSD, and ultra disk, until one is successfully provisioned. |
zoneid | Zone IDs, comma-separated for multi-zone clusters | The zone where the disk is created. For multi-zone clusters, specify multiple zones. Example: cn-hangzhou-a,cn-hangzhou-b,cn-hangzhou-c. |
encrypted | true, false | Whether to encrypt the disk. Default: false. |
Step 2: Create a PVC
A PVC requests storage from the StorageClass. ACK automatically provisions a persistent volume (PV) to satisfy the request.
Log on to the ACK console and click Clusters in the left-side navigation pane.
Click the name of your cluster. In the left-side pane, choose Volumes > Persistent Volume Claims.
On the Persistent Volume Claims page, click Create. In the Create PVC dialog box, configure the following parameters.
Parameter Description PVC Type Select Cloud Disk. NAS and OSS are also supported. Name The name of the PVC. Must be unique within the namespace. Allocation Mode Select Use StorageClass to dynamically provision a new volume. Alternatively, select Existing Volumes to bind an existing PV, or Create Volume to provision a volume directly. Existing Storage Class Click Select, find the StorageClass created in Step 1, and click Select in the Actions column. Capacity The storage size to request. Must not exceed the disk capacity. Access Mode Default: ReadWriteOnce (the volume can be mounted as read-write by a single node at a time). Click Create. After the PVC is created, the PVC (for example,
test-cloud) appears in the list of PVCs. The PVC is associated with the specified persistent volume (PV).
Step 3: Create a workload and mount the volume
Mount the PVC to a StatefulSet so that data written to the mount path persists in the cloud disk.
Log on to the ACK console and click Clusters in the left-side navigation pane.
Click the name of your cluster. In the left-side pane, choose Workloads > StatefulSets.
In the upper-right corner, click Create from Image.
In the Data Volumes section, you can add local storage, PVCs, or PVC templates. In this example, add a PVC volume and set the mount path. This example mounts the PVC to
/tmpin the container — data written to/tmpis stored in the cloud disk. For other workload parameters, see Create a stateless application by using a Deployment.
Complete the remaining configuration and click Create. After the workload starts, the cloud disk volume is mounted and ready to use.
What's next
To perform the same configuration using
kubectl, see Dynamically provision a disk volume by using the CLI.