Managing CBS by Using PVs and PVCs

Last updated: 2023-09-26 14:51:50

Scenario

Tencent Kubernetes Engine (TKE) allows you to create persistent volumes (PVs) and persistent volume claims (PVCs) and use existing PVCs when creating workloads and adding volumes so that you can manage Cloud Block Storage (CBS) disks by using the PVs and PVCs.
Note
CBS disks cannot be mounted across availability zones. If a pod with a CBS-type PV mounted is migrated to another availability zone, the mounting will fail.
To expand a cloud disk, you need to go to the Cloud Block Storage console. For more information, see Expanding Cloud Disks.

Instructions

Console Operation Guide

Creating a StorageClass via the console

To statically create a PV of the CBS type, you need to bind an available StorageClass of the same type. For more information, see Creating a StorageClass.

Creating a PV manually

Note
Creating a PV statically is suitable for scenarios where there’re already existing cloud disks used in the cluster.
1. Log in to the TKE console and click Cluster in the left sidebar.
2. On the Cluster Management page, click the ID of the target cluster to go to the cluster details page.
3. Select Storage > PersistentVolume from the left menu to access the "PersistentVolume" page, as shown below:


4. Click Create to enter the "Create PersistentVolume" page, and set the parameters as required, as shown below:

The main parameter information is as follows:
Creation Method: select Manual.
Name: Set a custom name. This document uses cbs-pv as an example.
Provisioner: select Cloud Block Storage.
R/W permission: Cloud disks only support single-machine read and write.
StorageClass: Select a StorageClass as required. This document uses cbs-test, which you created in the step of Creating a StorageClass, as an example.
Note
The PVC and PV will be bound to the same StorageClass.
Not specifying means that the StorageClass value for the corresponding PV is empty, and the storageClassName field in the YAML file has an empty string value.
Cloud Disk: select a created cloud disk.
File System: the default value is ext4.
5. Click Create a PersistentVolume to complete the creation.

Creating a PVC

1. In the cluster details page, select Storage > PersistentVolumeClaim from the left menu to access the "PersistentVolumeClaim" page, as shown below:


2. Click Create to enter the "Create PersistentVolumeClaim" page, and set the parameters as required, as shown below:

The main parameter information is as follows:
Name: set a custom name. This document uses cbs-pvc as an example.
Namespace: Select "default".
Provisioner: select Cloud Block Storage.
R/W permission: CBS disks only support Single machine read and write.
StorageClass: Select a StorageClass as required. This document uses cbs-test, which you created in the step of Creating a StorageClass, as an example.
Note
The PVC and PV will be bound to the same StorageClass.
Not specifying means that the StorageClass value for the PVC is empty, which corresponds to an empty string for the storageClassName field in the YAML file.
PersistentVolume: Specify a PersistentVolume as required. This document uses cbs-pv, which you created in the step of Static PV Creation, as an example.
Note
Only PVs in the specified StorageClass and in the Available or Released statuses can be selected. If no PV in the current cluster meets the conditions, select “No PersistVolume is specified”.
If the status of the selected PV is Released, you need to manually delete the claimRef field in the corresponding YAML configuration file of the PV so that the PV can be successfully bound with the PVC. For more information, see Rules for Binding PVs and PVCs.
3. Click Create a PersistentVolumeClaim to complete the creation.

Creating a workload to use a PVC volume

Note
This step creates a Deployment workload as an example.
1. On the Cluster management page, select the target cluster ID to go to the Deployment page of the cluster for which the workload needs to be deployed.
2. Click Create to enter the "Create Workload" page. Follow the instructions in Creating a Deployment to create a deployment, and refer to the information below to mount a volume, as shown in the following image:


Volume (optional):
Mount method: Select "Use existing PVC".
Volume name: set a custom name. This document uses cbs-vol as an example.
Select PVC: Choose the "cbs-pvc" created in the Create PVC step.
Containers in the Pod: Click Add mount target to set a mount target.
Volume: Select the added volume "cbs-vol" in this step.
Destination path: Enter a destination path. This document uses /cache as an example.
Sub-path: mount only a sub-path or a single file in the selected volume, such as /data or /test.txt.
3. Click Create Workload to complete the process.
Note
If you use the PVC mount method of CBS, the volume can be mounted to only one node.

kubectl Operation Guide

You can use the following sample YAML file to perform creation by using Kubectl.

(Optional) Creating a PV

You can create a PV by using an existing CBS disk, or directly create a PVC. The system automatically creates the PV. The sample YAML file is as follows:
apiVersion: v1
kind: PersistentVolume
metadata:
name: cbs-test
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 10Gi
csi:
driver: com.tencent.cloud.csi.cbs
fsType: ext4
readOnly: false
volumeHandle: disk-xxx # Specify an existing CBS ID
storageClassName: cbs

Creating a PVC

If you did not create a PV, the system automatically creates the corresponding PV when creating a PVC. The sample YAML file is as follows:
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: nginx-pv-claim
spec:
storageClassName: cbs
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
The capacity of the cloud disk must be a multiple of 10.
The minimum capacity of a premium cloud disk is 10 GB, and the minimum capacity of an SSD cloud disk or enhanced SSD cloud disk is 20 GB. For details, see the Creating Cloud Disks.

Using a PVC

You can create a workload to use a PVC volume. The sample YAML file is as follows:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 1
selector:
matchLabels:
qcloud-app: nginx-deployment
template:
metadata:
labels:
qcloud-app: nginx-deployment
spec:
containers:
- image: nginx
imagePullPolicy: Always
name: nginx
volumeMounts:
- mountPath: "/opt/"
name: pvc-test
volumes:
- name: pvc-test
persistentVolumeClaim:
claimName: nginx-pv-claim # An existing PVC