Alibaba Cloud disks are block-level data storage resources for Elastic Compute Service (ECS). Alibaba Cloud disks provide low latency, high performance, high durability, and high reliability. ACK Serverless allows you to use the Container Storage Interface (CSI) plug-in to create dynamically provisioned disk volumes. This topic describes how to use a dynamically provisioned disk volume and how to verify that a dynamically provisioned disk volume can be used for persistent storage.
Scenarios
Disks are suitable for the following scenarios:
You want to create applications that require high disk I/O throughput and do not require data sharing. The applications can use storage services such as MySQL and Redis.
You want to write logs at high speeds.
You want to persist data in a way that is independent of the pod lifecycle.
In addition to static volume provisioning based on existing disks, Kubernetes supports dynamic volume provisioning based on StorageClasses. Dynamic provisioning allows you to dynamically create and allocate storage resources. After you associate a StorageClass with a persistent volume claim (PVC), the system automatically creates and binds a persistent volume (PV) based on the configurations of the PVC and StorageClass. Dynamic provisioning automates the creation and configuration of storage resources to meet the storage requirements of your applications. Dynamic provisioning also reduces the complexity of storage infrastructure orchestration.
ACK Serverless clusters do not provide default StorageClasses. You must manually create StorageClasses in ACK Serverless clusters based on your business requirements.
Kubernetes provides the default StorageClass feature. If a PVC does not specify a StorageClass, the default StorageClass is used to provision a PV for the PVC. For more information about Kubernetes storage, see Storage basics.
Prerequisites
An ACK Serverless cluster is created. For more information, see Create an ACK Serverless cluster.
A kubectl client is connected to the ACK Serverless cluster. For more information, see Use kubectl to connect to an ACK cluster.
The CSI plug-in is manually installed. For more information, see Install and update csi-provisioner.
Procedure
ACK console
Step 1: Create a StorageClass
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click its name. In the left-side pane, choose .
In the upper-right corner of the StorageClasses page, click Create.
In the Create dialog box, configure the parameters.
The following table describes the parameters.
Parameter
Description
Name
The name of the StorageClass. The name must follow the format requirements displayed in the ACK console.
PV Type
The type of the persistent volume (PV). Select Cloud Disk.
Parameter
By default, a type parameter is added and set to cloud_essd. The type parameter specifies the disk category. Valid values of the type parameter:
cloud_essd
: Enterprise SSD (ESSD).cloud_regional_disk_auto
: Regional ESSDselastic_ephemeral_disk_premium
: premium elastic ephemeral disk.elastic_ephemeral_disk_standard
: standard elastic ephemeral disk.cloud_ssd
: standard SSD.cloud_efficiency
: ultra disk.
You can set the type parameter to any combination of the preceding values. For example, you can specify
type: cloud_ssd,cloud_essd
. In this case, the system tries to create a disk in the specified order of the categories. The system stops trying once a disk is created.NoteSpecific ECS instance types do not support ESSDs or elastic ephemeral disks. For more information, see FAQ about Elastic Block Storage.
You can add custom parameters. For example, you can add the zoneId parameter to specify the IDs of the zones in which you want to create disks. If your cluster is deployed in a single zone, set the value to the ID of the zone. Example:
cn-beijing-a
. If your cluster is deployed across zones, you can set the zoneId parameter to multiple zone IDs based on your business requirements. Example:cn-beijing-a, cn-beijing-b
.Reclaim Policy
The reclaim policy of the disk. Default value: Delete. You can also set the parameter to Retain.
Delete mode: When PVCs are deleted, the related PVs and disks are also deleted.
Retain mode: When PVCs are deleted, the related PVs and disks are retained. The PVs and disk data can only be manually deleted.
If you require higher data security, we recommend that you use the Retain mode to prevent data from being accidentally deleted.
Binding Mode
The volume binding mode. Default value: Immediate, which specifies that the system creates a disk before it creates a pod.
After you configure the parameters, click Create.
After the StorageClass is created, you can view the StorageClass on the StorageClasses page.
Step 2: Create a PVC
In the left-side navigation pane of the details page, choose .
In the upper-right corner of the Persistent Volume Claims page, click Create.
In the Create PVC dialog box, set the following parameters:
Parameter
Description
PVC Type
The type of the PVC. You can set the parameter to Cloud Disk or NAS. In this example, this parameter is set to Cloud Disk.
Name
The name of the PVC. The name must be unique in the namespace.
Allocation Mode
In this example, Use StorageClass is selected.
Existing Storage Class
Click Select. In the Select Storage Class dialog box, find the StorageClass that you want to use and click Select in the Actions column.
Capacity
The capacity claimed by the PVC.
Access Mode
The access mode of the PV provisioned by using the PVC. Default value: ReadWriteOnce.
Click Create.
After the PVC is created, you can view the PVC on the Persistent Volume Claims page. The PVC is bound to a PV.
Step 3: Create an application
In the left-side navigation pane of the details page, choose .
In the upper-right corner of the StatefulSets page, click Create from Image.
- Configure the application parameters. This example shows how to configure the volume parameters. For more information about other parameters, see Use a StatefulSet to create a stateful application.
You can configure local storage volumes and cloud storage volumes for an ACK cluster. In this example, Cloud Storage is selected.
Mount the disk volume that is created in this example to the /tmp path of the container. After the disk volume is mounted, the container data that is generated in the /tmp path is stored in the disk volume. - Configure other parameters and click Create. After the application is created, you can use the volume to store application data.
kubectl
Step 1: Create a StorageClass
In a multi-zone cluster, you can create a StorageClass by first creating a cloud disk and then creating a pod.
Use the following template to create a file named storage-class-csi.yaml:
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: alicloud-disk-ssd-b provisioner: diskplugin.csi.alibabacloud.com parameters: type: cloud_essd,cloud_ssd,cloud_efficiency encrypted: "false" reclaimPolicy: Retain allowVolumeExpansion: true volumeBindingMode: Immediate
Parameter
Description
provisioner
Set the value to
diskplugin.csi.alibabacloud.com
. This value specifies that the provisioner plug-in for Alibaba Cloud disks is used to create the StorageClass.type
This parameter specifies the disk category. Valid values:
cloud_auto
: ESSD AutoPL disk.cloud_essd
: ESSD. This is the default value.cloud_essd_entry
: ESSD Entry disk.cloud_ssd
: standard SSD.cloud_efficiency
: ultra disk.elastic_ephemeral_disk_standard
: standard elastic ephemeral disk.elastic_ephemeral_disk_premium
: premium elastic ephemeral disk.cloud_regional_disk_auto
: Regional ESSDs.
You can set this parameter to any combination of the preceding values. For example, you can set this parameter to
type: cloud_ssd,cloud_essd,cloud_auto
. In this case, the system tries to create a disk in the specified order of the categories. The system stops trying once a disk is created.ImportantYou can specify disk categories based on the zones and instance types of the nodes in your cluster and your requirements for disk billing and performance. For more information, see the following topics:
encrypted
Optional. This parameter specifies whether the disk is encrypted. The default value is false, which indicates that the disk is not encrypted.
reclaimPolicy
The reclaim policy of the disk. By default, this parameter is set to Delete. You can also set this parameter to Retain.
Delete mode: When PVCs are deleted, the related PVs and disks are also deleted.
Retain mode: When PVCs are deleted, the related PVs and disks are retained. The PVs and disk data can only be manually deleted.
If you require high data security, we recommend that you use the Retain mode to prevent data from being accidentally deleted.
allowVolumeExpansion
If you set this parameter to true, the disk can be automatically expanded.
volumeBindingMode
The volume binding mode. Default value: Immediate, which specifies that the system creates a disk before it creates a pod.
Run the following command to create a StorageClass:
kubectl apply -f storage-class-csi.yaml
View the created StorageClass.
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click its name. In the left-side pane, choose .
After the StorageClass is created, you can view the StorageClass on the StorageClasses page.
Step 2: Create a PVC
Use the following template to create a file named pvc-ssd.yaml:
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: disk-pvc spec: accessModes: - ReadWriteOnce volumeMode: Filesystem resources: requests: storage: 25Gi storageClassName: alicloud-disk-ssd-b
Parameter
Description
name
The name of the PVC.
accessModes
The access mode of the PV provisioned by using the PVC.
volumeMode
Optional. The format in which the disk is mounted. File systems are supported.
storageClassName
The name of the StorageClass that you want to associate with the PVC.
storage
The disk size claimed by the PVC. The minimum capacity is 20 GiB.
Run the following command to create a PVC:
kubectl create -f pvc-ssd.yaml
View the created PVC.
In the left-side navigation pane of the cluster details page, choose
. You can view the created PVC on the Persistent Volume Claims page.
Step 3: Create an application
Create a file named pvc-dynamic.yaml.
Use the following template to create an application named nginx-dynamic and mount the PVC to the application:
apiVersion: apps/v1 kind: StatefulSet metadata: name: nginx-dynamic spec: selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80 name: web volumeMounts: - name: pvc-disk mountPath: /data volumes: - name: pvc-disk persistentVolumeClaim: claimName: disk-pvc
Parameter
Description
mountPath
The path to which the disk is mounted.
claimName
The name of the PVC mounted to the application.
Run the following command to deploy the application and mount the PVC to the application:
kubectl create -f pvc-dynamic.yaml
View the deployed application.
In the left-side navigation pane of the cluster details page, choose
. You can view the created application on the StatefulSets page.
References
If errors occur when you use disk volumes, refer to FAQ about disk volumes.
For more information about how to resize a disk when the disk size does not meet your business requirements or the disk is full, see Expand disk volumes.
For more information about real-time disk usage, see Overview of container storage monitoring.