All Products
Search
Document Center

Container Service for Kubernetes:StorageClass

Last Updated:Nov 19, 2024

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

Ultra disks

The previous generation disk.

alicloud-disk-ssd

Standard SSD

The previous generation disk.

alicloud-disk-essd

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.

  • If ESSDs are out of stock or not supported by the current node, the system attempts to create a standard SSD.

  • If standard SSDs are out of stock or not supported by the current node, the system attempts to create an ultra disk.

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: alicloud-disk-topology-alltype
    parameters:
      type: cloud_essd,cloud_ssd,cloud_efficiency
    provisioner: diskplugin.csi.alibabacloud.com
    reclaimPolicy: Delete
    allowVolumeExpansion: true
    volumeBindingMode: WaitForFirstConsumer

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 the zoneId parameter of the StorageClass configuration, a disk is created in the specified zone.

  • If you set volumeBindingMode: Immediate and specify multiple zones in the zoneId 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

provisioner

Storage resource provider. You must set the value to diskplugin.csi.alibabacloud.com, which indicates that the provisioner plug-in for Alibaba Cloud disks is used to create the StorageClass.

parameters

See the Other parameters description table below.

reclaimPolicy

The reclaim policy of the disk. By default, this parameter is set to Delete. You can also set this parameter to Retain.

  • Delete: When PVCs are deleted, the related PVs and disks are also deleted.

  • Retain: 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 unintentional data loss.

allowVolumeExpansion

If you set this parameter to true, the disk can be automatically expanded.

volumeBindingMode

The binding mode of the disk. By default, this parameter is set to Immediate. You can also set this parameter to WaitForFirstConsumer.

  • Immediate: A disk is created when the PVC that uses the StorageClass is created. This way, a disk is created and a PV is provisioned before you create a pod that uses the disk.

  • WaitForFirstConsumer: Delays the binding and provisioning of a PV until a pod that uses the PVC is created. After the pod is scheduled to a node, a disk is created in the zone where the node is deployed and provisioned as the PV.

Other parameters description

Parameter

Required

Description

type

Yes

The type of the disk. By default, the type parameter is added and set to cloud_essd. Valid values of the type parameter:

  • ultra disk: cloud_efficiency

  • ESSD AutoPL: cloud_auto

  • standard SSD: cloud_ssd

  • ESSD: cloud_essd

  • ESSD Entry: cloud_essd_entry

You can specify one or more values. For example, you can set this parameter to type: cloud_efficiency, cloud_ssd, cloud_essd. The system attempts to create a disk of the specified types in sequence until a disk is created.

fstype

No

The file system of the disk. Valid values: ext4 and xfs. Default value: ext4.

mkfsOptions

No

Parameters that are specified to format the disk. Example: mkfsOptions: "-O project,quota".

diskTags

No

The custom tag of the disk. Example: diskTags: "a:b,b:c". You can also use the format diskTags/a: b (starting from v1.30.3).

encrypted

No

Specifies whether the created disk is encrypted. The default value is false, which indicates that the disk is not encrypted.

performanceLevel

No

The performance level (PL) of the ESSD. Valid values: PL0, PL1, PL2, and PL3. Default value: PL1. For more information, see Capacity and PLs.

volumeExpandAutoSnapshot [Deprecated]

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.

provisionedIops

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.

burstingEnabled

No

Specifies whether to enable Performance Burst for the disk. Default value: false. Valid values:

  • true: Enables performance burst for the disk.

  • false: Disables performance burst for the disk.

Note

This parameter is supported only by ESSD AutoPL disks. For more information, see Disk specifications.

multiAttach

No

Set it to true to enable multi-attach. For more information, see Multi-attach for cloud disks.

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.

  1. Configure a default StorageClass.

    Run the following command to set alicloud-disk-topology-alltype as the default StorageClass.

    Note

    alicloud-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
  2. Use the default StorageClass.

    1. 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-