A StorageClass describes the type of storage. A cluster admin can define various storage types for the cluster. In Tencent Cloud TKE, the default StorageClass is block storage. Configuring both StorageClass and PersistentVolumeClaim allows you to create your desired storage type and capacity dynamically.
Create a PVC as instructed in the "[Creating a PVC](https://www.tencentcloud.com/document/product/457/30679#Creating a PVC)" section in PV and PVC Management. Select StorageClass when setting the PVC parameters.
Create a StatefulSet as instructed in the "Creating a StatefulSet" section in StatefulSet Management. When setting the StatefulSet parameters, click Add a volume and select "Use a new PVC" to set the PVC. See the figure below:
The following is a sample where which you can perform creation directly using kubectl.
If you haven't created any StorageClass, a StorageClass named CBS will exist in the cluster by default.
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
# This supports CLOUD_BASIC, CLOUD_PREMIUM, and CLOUD_SSD; if not recognized, it will default to CLOUD_BASIC
# paymode: PREPAID
# paymode is the billing method of the cloud disk, which can be PREPAID (prepaid method, which only supports the "Retain" reclaiming policy) or POSTPAID (postpaid method, which supports "Retain" or "Delete" reclaiming policy. This is the default value. Retain is only available in cluster version 1.8 or higher)
# 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
Supported parameters included:
You can create a multi-Pod StatefulSet using CBS 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: # Automatically create a PVC to automatically create a PV
- metadata:
name: www
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: cloud-premium
resources:
requests:
storage: 10Gi
Was this page helpful?