This topic describes the best practice for using disk volumes in ACS clusters, including suggested StorageClass configurations and suggested configurations for mounting disk volumes as ephemeral storage or persistent storage.
Introduction to disk volumes
Alibaba Cloud Elastic Block Storage (EBS) provides a high-throughput, low-latency persistent storage solution for computing instances. It is the core infrastructure that supports compute-intensive scenarios, such as high-performance computing (HPC), AI, and big data analysis. For more information, see Overview of Block Storage
ACS supports the following types of disks:
cloud_essd_entry: ESSD Entry disk.cloud_auto: ESSD AutoPL disk.cloud_essd: Enterprise SSD (ESSD). This is the default value.cloud_ssd: standard SSD.cloud_efficiency: ultra disk.
Standard SSDs and ultra disks are previous-generation disks, which are discontinued in some regions and zones. ACS GPU-accelerated pods do not support standard SSDs or ultra disks. We recommend that you preferably use the ESSD series to ensure compatibility.
Suggested StorageClass configurations
You can configure StorageClasses to dynamically provision storage resources and conduct topology-aware scheduling.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: alicloud-essd
parameters:
type: cloud_auto,cloud_essd
fstype: xfs
provisioner: diskplugin.csi.alibabacloud.com
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: trueThe key parameters of a StorageClass must follow these principles:
Storage type binding: Explicitly claim the disk type by specifing
parameters.type. In this example,cloud_auto,cloud_essdindicates thatcloud_auto(ESSD AutoPL disks) is preferably used, andcloud_essd(ESSD disks) is used when ESSD AutoPL disks are out of stock. ESSD disks support performance levels (from PL0 to PL3) defined byperformanceLevel. You can define performance levels to meet I/O requirements in HPC, AI training, and other scenarios.Binding mode optimization: We recommend that you set
volumeBindingModetoWaitForFirstConsumerin order to schedule pods and then create disks based on the zones of the pods. With the help of the elastic provisioning mechanism of Alibaba Cloud, you can adjust the topology of pods and volumes based on affinity rules in case pods and volumes (PVs and PVCs) are spread across different zones.File system selection: Explicitly claim the file system type by specifying
parameters.fstype. XFS file systems are suggested because they support large metadata blocks and delayed logging, which can augment large-scale parallel I/O performance.
How to use disk volumes in ACS clusters
Overview
Characteristic | Ephemeral storage | Persistent storage |
Data TTL | Disks are bound to pods, and disks are deleted together with pods. | Disks are independent of pods. You need to manually delete PVs and PVCs. |
Data restoration | Not supported. Data is permanently deleted and cannot be restored. | Supported. PVCs are reserved for recreating pods. |
Storage cost | Disks are created on demand and billed based on the lifecycle of the pods. | Disks are billed until they are released. |
Applicable scenarios | Temporary caching and intermediate computing result storage. | Databases, logging systems, and stateful applications. |
ACK clusters whose version is 1.24 or earlier do not support ephemeral storage.
Based on the preceding characteristics, we recommend that you follow these rules when you choose between ephemeral storage and persistent storage:
Prioritize ephemeral storage: If your system can tolerate business data loss and requires fast scaling, such as stateless web applications, we recommend that you choose ephemeral storage.
Use persistent storage only: In scenarios that require data persistence, cross-pod data sharing, or high availability, such as running MySQL clusters within Kubernetes clusters, you must use persistent storage.
A proper storage solution can efficiently help you balance resource utilization and data reliability in ACS clusters. In addition, with the help of Alibaba Cloud storage services, such as disk snapshots and cross-zone replication, the disaster recovery capability of your system can be further improved.
Ephemeral storage
Ephemeral storage is a lightweight storage solution in Kubernetes. This solution is based on volumes of the ephemeral type. The mechanism behind this solution is binding the lifecycle of storage resources to pods. When a pod is deleted, the PVC and PV associated with the pod are also deleted. The deleted data cannot be restored. This solution is suitable for temporary storage scenarios, such as temporary caching, log caching, intermeidate computing result storage, and temporary data processing.
This solution has the following advantages:
Resource isolation: Each pod occupies separate storage resources. This helps avoid performance contention or data contamination caused by storage resource sharing.
Simplified declarative configuration:
volumeClaimTemplateis built into the pod template, which eliminates the need to create PVCs and PVs in advance and simplifies the resource management procedure.
The following YAML template creates a Deployment and mounts a disk volume as ephemeral storage to the pods created by the Deployment.
In the YAML template, take note of the following key parameters:
volumes:
- name: scratch-volume
ephemeral: # Explicitly claim ephemeral storage.
volumeClaimTemplate:
metadata:
labels:
type: scratch-volume
spec:
accessModes: [ "ReadWriteOncePod" ]
storageClassName: alicloud-essd
resources:
requests:
storage: 30GiStorageClass selection: Configure
StorageClassNameto specify an existing StorageClass.Access mode configuration: We recommend that you set
accessModestoReadWriteOncePod(RWXO). The RWXO mode is suggested for ephemeral volumes. In this mode, a volume can be read and written by only one pod, which ensures data consistency.Storage capacity planning: Adjust the value of
storagebased on the actual needs of pods. If the value is too small, the storage space will be insufficient. An excessively large value results in resource waste. We recommend that you monitor the usage ofephemeral-storagein Prometheus or CloudMonitor and adjust the value accordingly.
Persistent storage
Persistent storage is implemented through the StatefulSet controller, with the core being that the lifecycle of PVC and PV is independent of the pod. Even if a pod is terminated due to scaling in, failure, or manual deletion, the PVC and PV still retain the data and can be rebound to a new pod. This mechanism is suitable for stateful applications (such as databases, message queues) or scenarios that require cross-pod data sharing.
StatefulSet ensures storage persistence through the following mechanisms:
Independent PVC management: Each pod is associated with a separate PVC, which is generated based on
volumeClaimTemplates. However, the lifecycle of the PVC is decoupled from the pod.Ordered restoration: The StatefulSet controller prioritizes volume restoration when recreating pods in order to ensure data consistency.
The following YAML template creates a StatefulSet and mounts a disk volume as persistent storage to the pods created by the StatefulSet.
In the YAML tempalte, take note the following key parameters:
volumeClaimTemplates:
- metadata:
name: mysql-data
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: alicloud-essd
resources:
requests:
storage: 50GiStorageClass selection: Configure
StorageClassNameto specify an existing StorageClass.Access mode configuration: We recommend that you set
accessModestoReadWriteOnce(RWO) to ensure that the volume is mounted only to one node.Data persistence: The PVC will be retained after the pod is deleted. If you recreate the pod by running the
kubectl delete pod -n <namespace> <pod-name>command, and the new pod will be reassociated with the retained PVC.