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.
Disk Type: Premium Cloud Disk and SSD Cloud Disk are supported. Different availability zones may have different disk types. For more information, see Cloud Disk Types. Select a disk type as prompted by the console.
Reclaim Policy: the reclaim policy for cloud disks. Generally, the Delete and Retain reclaim policies are provided, which depends on the selected billing mode. For data security, we recommend that you select Retain.
Volume Binding Mode: two modes are available: Bind Now and Wait for Scheduling. Different modes support different volume binding policies. Refer to the following information to select the appropriate mode:
Scheduled Snapshot: setting scheduled snapshot policy can effectively protect data security, but data backup will generate certain fees. For more information, see Snapshot Overview.
The default-policy configuration provided by TKE for backup includes: the date of backup execution, time point of backup execution, and backup retention period.
Click Create a StorageClass to complete the process.
On the Cluster Management page, select the ID of the cluster for which a PVC needs to be created.
On the cluster details page, choose Storage -> PersistentVolumeClaim in the left sidebar to go to the PersistentVolumeClaim page, as shown in the following figure.
Click Create to go to the Create a PersistentVolumeClaim page, where you can set key PVC parameters as required, as shown in the following figure.
Main parameters are described as follows:
Name: set a custom name. This document uses
cbs-pvc as an example.
Namespace: select default.
Provisioner: select CBS.
R/W permission: CBS disks only support Single machine read and write.
StorageClass: specify a StorageClass as required. This document uses the
cbs-test created 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.
PersistVolume: specify a PersistentVolume as required. In the example in this document, no PersistentVolume is specified.
- 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.
Disk Type: based on the selected StorageClass, the available disk types are displayed: Premium Cloud Disk and SSD Cloud Disk.
Capacity: if no PersistentVolume is specified, specify the expected cloud disk capacity.
Cost: based on the above parameters, calculate the cost of the corresponding cloud disk. For more information, see Billing Modes.
Click Create a PersistentVolumeClaim to complete the creation process.
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.
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 provisioner: cloud.tencent.com/qcloud-cbs ## The provisioner coming with the TKE cluster parameters: type: CLOUD_PREMIUM # CLOUD_BASIC, CLOUD_PREMIUM, and CLOUD_SSD are supported. If it is not recognized, CLOUD_BASIC is used by default. # paymode: POSTPAID # paymode: the billing method of the cloud disk. The default value is POSTPAID (pay-as-you-go, which supports the **Retain** and **Delete** reclaim policies. **Retain** is only available in clusters later than V1.8). # aspid:asp-123 # You can specify a snapshot policy. After the cloud disk is created, it will be automatically bound to this policy. Binding failure does not affect the creation.
The following table lists the supported parameters.
|type||StorageClass type, which can be
|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
|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:
apiVersion: apps/v1beta1 kind: StatefulSet metadata: name: web spec: 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