PV and PVC Management

Last updated: 2020-02-25 09:20:14

PDF

Overview

Storage resources within the PersistentVolume (PV): cluster. For example, a node is a resource of a cluster. A PV is independent of the lifecycle of the Pod, and different types of PVs can be created based on different StorageClass types.
PersistentVolumeClaim (PVC): A storage request within a cluster. For example, a PV is similar to a Pod that uses node resources, while a PVC declares that a PV resource is used. A PVC can also dynamically create PVs when PV resources are insufficient.

Considerations

If a Pod with a CBS-type PV mounted is migrated to another availability zone, the mount will fail.

  • TKE console does not support expansion or reduction of CBS disk. Please go there by yourself. CBS console Perform the operation.

Operation Guide for PVs and PVCs in the Console

Creating a PV Statically

Static creation of PV is suitable for scenarios that have existing cloud disks and are used in the cluster.

  1. Log in to the TKE console and select Clusters In the left sidebar.
  2. Click the ID of the cluster where PV needs to be created to enter the cluster management page.
  3. Select "Storage" > "PersistentVolume" to go to the PersistentVolume information page.
  4. Click CREATE To go to the "Create a PersistentVolume" page.
  5. Set the PV parameters according to the actual requirements. Main parameters include:
    • Creation Method Refer to the following information to select on-demand. This article takes "static creation" as an example.
    • Name : enter a name.
    • Provisioner Select the PV type as needed. This article takes [HDD cloud disk CBS] as an example.
    • R/W permission Please select as needed, among which HDD cloud disk only supports [reading and writing on a stand-alone machine].
    • Select a cloud disk: Select based on actual needs.
    • StorageClass: Select based on actual needs.
  6. Click Create a PersistentVolume. Now you successfully created a PersistentVolume.

  1. Log in to the TKE console and select Clusters in the left sidebar.
  2. Click the ID of the cluster where PVC needs to be created to enter the cluster management page.
  3. Select "Storage" > "PersistentVolumeClaim" to go to the PersistentVolumeClaim information page.
  4. Click Create to go to the "Create a PersistentVolumeClaim" page.
  5. Set the PVC parameters according to the actual requirements. Key parameters are as follows:
    • Name : enter a name.
    • Namespace: Select the namespace type based on actual needs.
    • Provisioner Select the PVC type as needed. This article takes [HDD cloud disk CBS] as an example.
    • R/W permission Please select as needed, among which HDD cloud disk only supports [reading and writing on a stand-alone machine].
    • StorageClass: Select based on actual needs.
    • Capacity Set up according to the actual needs. The minimum capacity of cloud disk is determined by HDD cloud disk's product specifications.
  6. Click Create a PersistentVolume. Now you successfully created a PersistentVolume.

    If the existing PVs are insufficient, the system will automatically create a PV.

Creating a Workload to Use a PVC Volume

  1. Log in to the TKE console and select Clusters in the left sidebar.
  2. Click the ID of the cluster where you want to deploy a workload to enter the cluster management page.
  3. Under "Workload", select a workload type to go to the corresponding information page.
  4. Click Create to go to Create Workload page.
  5. Set the workload name, namespace and other information as instructed. In Volume, click Add Volume as shown below:
  6. Select "Use an existing PVC" and enter the name to use an existing PVC.
  7. Click Create Workload to complete the creation.

    Using PVC mount mode, volume can only be mounted to one node host

Using kubectl to Manipulate PVs and PVCs

Currently, only PV and PVC of CBS and CFS types are supported. If you choose PV and PVC, of CBS type, you can use the StorageClass Management Specify the type of cloud disk bound to PV. The following is a sample where which you can perform creation directly using kubectl.

(optional) create PV

If no PV has been created, the system will create a corresponding PV automatically when creating a PVC.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: nginx-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  qcloudCbs:
      cbsDiskId: disk-xxxxxxx ## Specify an existing CBS id
      fsType: ext4
  storageClassName: cbs

If no PV has been created, the system will create a corresponding PV automatically when creating a PVC.

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: nginx-pv-claim
spec:
  storageClassName: cbs
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  • The capacity of an HDD cloud disk must be a multiple of 10, with a minimum of 10.
  • The youngest Premium Cloud Storage is 50GB.
  • The youngest SSD is 100GB.

Using a PVC

Below is a YAML sample:

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 already created PVC