A cluster admin can use StorageClass to define different storage classes for Tencent Kubernetes Engine (TKE) clusters. TKE provides the block storage StorageClass by default. You can use both StorageClass and PersistentVolumeClaim to dynamically create required storage resources. This document describes how to create a StorageClass of the Cloud Block Storage (CBS) type by using the console and Kubectl, and how to customize the template required by CBS disks.
cbs-testas an example.
The default-policy configuration provided by TKE for backup includes the date of backup execution, time point of backup execution, and backup retention period.
cbs-pvcas an example.
cbs-testcreated in the step of Creating a StorageClass as an example.
- The PVC and PV will be bound to the same StorageClass.
- If you do not specify a StorageClass, the value of
StorageClassfor the corresponding PVC is empty, and the value of the
storageClassNamefield in the corresponding YAML file is a null string.
- The system first searches the current cluster to see whether there are PVs that meet the binding rules. If no, the system dynamically creates a PV to be bound based on the PVC and the selected StorageClass.
StorageClassis not specified, then
PersistVolumemust be specified.
- No PersistentVolume is specified. For more information, see PV and PVC Binding Rules.
This step creates a StatefulSet workload as an example.
cbs-volas an example.
cbs-pvc, which you created in the step of Creating a PVC by using a specified StorageClass, as an example.
cbs-volthat you added in this step.
/cacheas an example.
If you use the PVC mount method of CBS, the volume can be mounted to only one node.
You can use the sample template in this document to create a StorageClass by using Kubectl.
The following sample YAML file is used to create a StorageClass with the default name of cbs in a cluster.
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: # annotations: # storageclass.beta.kubernetes.io/is-default-class: "true" # If this line is present, it will become the default-class, and if you do not specify a type when creating a PVC, this type will be used automatically. name: cloud-premium # If the CBS-CSI add-on is installed for the TKE cluster, enter `com.tencent.cloud.csi.cbs` for `provisioner`. # If the CBS-CSI add-on is not installed, enter `cloud.tencent.com/qcloud-cbs` for `provisioner` (this capability is deprecated in v1.20 and later versions). provisioner: com.tencent.cloud.csi.cbs parameters: type: CLOUD_PREMIUM renewflag: NOTIFY_AND_AUTO_RENEW paymode: POSTPAID_BY_HOUR aspid: asp-123 reclaimPolicy: Retain volumeBindingMode: WaitForFirstConsumer
The following table lists the supported parameters.
|type||This includes CLOUD_PREMIUM (Premium cloud disk), CLOUD_SSD (SSD cloud disk) and CLOUD_HSSD (enhanced SSD cloud disk).|
|zone||Availability zone. If an availability zone is specified, the cloud disk is created in this availability zone. If no availability zone is specified, the availability zones of all nodes are obtained and one is selected at random. For the identifiers of all Tencent Cloud regions, see Regions and Availability Zones.|
|paymode||The billing method of the cloud disk. The default value is
|volumeBindingMode||The volume binding mode. Two modes are supported: **Immediate** (bind now) and **WaitForFirstConsumer** (wait for scheduling).|
|reclaimPolicy||The reclaim policy. Two policies are supported: **Delete** and **Retain**.|
|renewflag||CBS renewl mode. The default value is
|aspid||Snapshot policy ID. The created cloud disk will be automatically bound with this policy. Binding failure does not affect the creation of the cloud disk.|
You can use a cloud disk to create a multi-pod StatefulSet. The sample YAML file is as follows:
The apiVersion of the resource object varies based on the cluster Kubernetes version. You can run the command
kubectl api-versionsto view the apiVersion of the current resource object.
apiVersion: apps/v1 kind: StatefulSet metadata: name: web spec: selector: matchLabels: app: nginx serviceName: "nginx" replicas: 3 template: metadata: labels: app: nginx spec: terminationGracePeriodSeconds: 10 containers: - name: nginx image: nginx ports: - containerPort: 80 name: web volumeMounts: - name: www mountPath: /usr/share/nginx/html volumeClaimTemplates: # the system automatically creates a PVC and then automatically creates a PV. - metadata: name: www spec: accessModes: [ "ReadWriteOnce" ] storageClassName: cloud-premium resources: requests: storage: 10Gi