All Products
Search
Document Center

Container Service for Kubernetes:StorageClasses

Last Updated:Nov 27, 2023

This topic describes different types of StorageClass for Container Service for Kubernetes (ACK) Serverless clusters. This topic also describes how to choose proper StorageClass types to meet your business requirements and how to configure a default StorageClass.

StorageClass

By default, ACK Serverless clusters do not provide StorageClasses. You can create StorageClasses based on your business requirements. The following code block shows a StorageClass template:

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

This StorageClass template attempts to create cloud_essd disks, cloud_ssd disks, and cloud_efficiency disks in sequence. If the current zone does not support cloud_essd disks, the system attempts to create cloud_ssd disks and cloud_efficiency disks in sequence. You can adjust the disk types in the template and their sequence on demand.

Default StorageClass

Kubernetes provides the default StorageClass feature. If no StorageClass is specified for a persistent volume claim (PVC), the default StorageClass is used to provision a persistent volume (PV) for the PVC. For more information, see Default StorageClass.

Note
  • 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 an Apsara File Storage NAS (NAS) file system. To avoid such situations, ACK Serverless clusters do not support the default StorageClass feature. To configure a default StorageClass, perform the following steps.

  • You can configure only one default StorageClass for each cluster. If you configure more than one default StorageClass for a cluster, all default StorageClasses become invalid.

  1. Configure a default StorageClass.

    Run the following command to set alicloud-disk-ssd as the default StorageClass:

    kubectl patch storageclass alicloud-disk-ssd -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

    After the default StorageClass is configured, alicloud-disk-ssd is marked as (default).

    kubectl get sc

    Expected output:

    NAME                          PROVISIONER                       AGE
    alicloud-disk-ssd (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-ssd.

      kubectl get pvc

      Expected output:

      NAME       STATUS   VOLUME                   CAPACITY   ACCESS MODES   STORAGECLASS        AGE
      disk-pvc   Bound    d-bp18pbai447qverm3ttq   20Gi       RWO            alicloud-disk-ssd   49s

What to do next

You can also run the following command to disable the default StorageClass:
kubectl patch storageclass alicloud-disk-ssd -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'