The StorageClass provides the capability of dynamic volume distribution. The Container Storage Interface (CSI) plug-in provided by Alibaba Cloud automatically creates the corresponding persistent volume (PV) based on the StorageClass. When you create a persistent volume claim (PVC), you can specify the StorageClassName parameter to automate the creation of the PV and its underlying storage. This reduces the workload of creating and maintaining PVs.
Introduction
StorageClass defines the class of the storage. You can set different parameters for it so that storage resources can be automatically provisioned and adjusted according to demand.
By default, Container Service for Kubernetes (ACK) provides the following StorageClass templates. Refer to Cloud disk selection to select an appropriate StorageClass. For the matching relationship between disk types and types of Elastic Compute Service (ECS) instances, see Overview of instance families.
StorageClass | Matched disk type | Description |
alicloud-disk-efficiency | The previous generation disk. | |
alicloud-disk-ssd | The previous generation disk. | |
alicloud-disk-essd | By default, the PL1 Enterprise SSD (ESSD) is created by this StorageClass. | |
alicloud-disk-topology-alltype | Provides a high-availability mode. In this mode, the system first attempts to create an ESSD.
| Recommended for multi-zone scenarios |
Description of zone rules
When you configure the StorageClass to create a disk, the following rules determine the zone in which the disk is created:
If you set
volumeBindingMode: WaitForFirstConsumer
in the StorageClass configuration, a disk is created in the same zone as the first pod that uses the PVC.If you set
volumeBindingMode: Immediate
and specify only one zone in thezoneId
parameter of the StorageClass configuration, a disk is created in the specified zone.If you set
volumeBindingMode: Immediate
and specify multiple zones in thezoneId
parameter of the StorageClass configuration, the system attempts to create a disk in the specified zones in a round robin manner.
If your cluster is deployed across zones, we recommend that you use the WaitForFirstConsumer
mode in the StorageClass configurations. You can create a StorageClass based on the required disk type. For more information about how to deploy storage resources in multiple zones, see Recommended storage settings for cross-zone deployment.
StorageClass YAML template
If the preceding StorageClass cannot meet your requirements, you can use the following template to create a StorageClass.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: alicloud-disk-topology-alltype
provisioner: diskplugin.csi.alibabacloud.com
parameters:
type: cloud_essd,cloud_ssd,cloud_efficiency
fstype: ext4
diskTags: "a:b,b:c"
encrypted: "false"
performanceLevel: PL1
provisionedIops: "40000"
burstingEnabled: "false"
reclaimPolicy: Delete
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer
Key parameters description
Parameter | Description | |
| Storage resource provider. You must set the value to | |
| See the Other parameters description table below. | |
| The reclaim policy of the disk. By default, this parameter is set to
If you require high data security, we recommend that you use the | |
| If you set this parameter to | |
| The binding mode of the disk. By default, this parameter is set to
|
Other parameters description
Parameter | Required | Description |
| Yes | The type of the disk. By default, the type parameter is added and set to cloud_essd. Valid values of the type parameter:
You can specify one or more values. For example, you can set this parameter to |
| No | The file system of the disk. Valid values: |
| No | Parameters that are specified to format the disk. Example: |
| No | The custom tag of the disk. Example: |
| No | Specifies whether the created disk is encrypted. The default value is |
| No | The performance level (PL) of the ESSD. Valid values: |
| No | Note This parameter has been deprecated since version 1.31.4 of the CSI component. Specifies whether to create a snapshot to back up the data stored in the disk before the disk is expanded. |
| No | The provisioned performance of the disk, such as the disk Input/Output Operations per Second (IOPS). Valid values: 0 to min{50,000, 1,000 × Capacity - Baseline IOPS}. Baseline IOPS = min{1,800 + 50 × Capacity, 50,000}. Note This parameter is supported only by ESSD AutoPL disks. For more information, see Disk specifications. |
| No | Specifies whether to enable Performance Burst for the disk. Default value: false. Valid values:
Note This parameter is supported only by ESSD AutoPL disks. For more information, see Disk specifications. |
| No | Set it to |
Billing
The StorageClass is free of charge. The disks automatically created by using the StorageClass are billed as pay-as-you-go disks. For more information about the billing method of the disk, see Billing.
Use the StorageClass
When you create a PVC, you can specify the required size of the volume and the StorageClassName parameter to select the appropriate StorageClass to create the volume. If you do not specify StorageClassName in the PVC, you can also use the default StorageClass to create the volume.
Use a specified StorageClass
When you create a PVC, specify the StorageClassName parameter to select the StorageClass to be used. The corresponding PV and the underlying storage are automatically created.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: disk-pvc
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 20Gi # The size of the requested disk volume.
storageClassName: alicloud-disk-topology-alltype # Specify which StorageClass to use.
Use the default StorageClass
Kubernetes applies the default StorageClass mechanism. If no StorageClass is specified for a PVC, the default StorageClass is used to provision a PV for the PVC. For more information, see Default StorageClass.
The default StorageClass takes effect on all PVCs. Proceed with caution if your cluster uses PVCs of different storage types. For example, the default StorageClass may create a disk PV for a PVC that defines a File Storage NAS (NAS) file system. Therefore, ACK clusters do not support the default StorageClass. If you want to configure a default StorageClass, perform the following steps.
Configure a default StorageClass.
Run the following command to set alicloud-disk-topology-alltype as the default StorageClass.
Notealicloud-disk-topology-alltype is used in this example.
kubectl annotate storageclass alicloud-disk-topology-alltype storageclass.kubernetes.io/is-default-class=true
After the default StorageClass is configured, querying the StorageClass in the cluster shows that alicloud-disk-topology-alltype is marked as (default).
kubectl get sc
Expected output:
NAME PROVISIONER AGE alicloud-disk-topology-alltype (default) diskplugin.csi.alibabacloud.com 96m
Use the default StorageClass.
Use the following template to create a PVC with no StorageClass specified:
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: disk-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 20Gi
The cluster automatically creates a disk PV based on the default StorageClass alicloud-disk-topology-alltype.
kubectl get pvc
Expected output::
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE disk-pvc Bound d-bp18pbai447qverm**** 20Gi RWO alicloud-disk-topology-alltype 49s
You can run the following command to disable the default StorageClass:
kubectl annotate storageclass alicloud-disk-topology-alltype storageclass.kubernetes.io/is-default-class-