tencent cloud

Feedback

Managing CFS Templates by Using a StorageClass

Last updated: 2022-08-26 17:51:26

    Overview

    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 File Storage (CFS) type by using the console and Kubectl as well as how to customize the template required by CFS disks.

    Prerequisites

    1. Install the CFS add-on

    If your cluster has been installed with the CFS-CSI add-on, skip this step; otherwise, install it as instructed in CFS Instructions.

    2. Create a subnet

    When creating a StorageClass, you need to set the CFS subnet to ensure that every AZ in the CFS's VPC has a suitable subnet. We recommend you create a subnet in advance as instructed in Creating Subnets.

    3. Create a permission group and add permission group rules

    When creating a StorageClass, you need to configure a suitable permission group for the file system. We recommend you create a permission group in advance as instructed in Managing Permissions.

    4. Get the file system FSID

    1. In the CFS console, click the ID of the target file system to enter its details page.
    2. Select the Mount Target Info tab and get the file system FSID next to Mount under Linux, such as 2qray8xj.
      Note:

      For better stability, when you create a PV by YAML and use the NFSv3 protocol for mounting, you need to specify the FSID of the file system to be mounted.

    Console Operation Guide

    Creating a StorageClass

    1. Log in to the TKE console and select Cluster on 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 > StorageClass on the left sidebar.
    4. Click Create to enter the Create StorageClass page, where you can configure StorageClass parameters.
      Configuration Item Description
      Name Enter the StorageClass name, for example, `cfs-storageclass`.
      Region It is the region of the cluster by default.
      Provisioner Provisioner can be CBS (CSI) or Cloud File Storage. Here, Cloud File Storage is selected.
      Instance creation mode It can be New instance or Shared instance.
      • New instance: During mounting, a CFS instance is created for each PVC by default.
      • Shared instance: During mounting, PVCs correspond to different sub-directories of the same CFS instance. The shared CFS instance and its sub-directories are created automatically by the system.
      • Note

        The shared instance mode is supported by the CFS-CSI add-on on v1.0.1 or later. Upgrade your add-on in time. Use instructions are as follows:

      • For a StorageClass in shared instance mode, the Reclaim policy is Retain.
      • When the StorageClass is used to dynamically create a PVC for the first time, a CFS instance will be created by default, along with its sub-directories to implement isolated mounting of PVCs.
      • CFS instances created by different StorageClasses in shared instance mode are different. We recommend you limit the number of instances.
      Availability zone In the current region, select an AZ that supports CFS. Different AZs in the same region support different storage classes. For more information, see Recommended Regions .
      CFS subnet Set the subnet range of the CFS in the current AZ.
      Storage type CFS provides Standard Storage and Performance Storage. Different AZs in the same region support different storage types. Select one as needed.
      • Standard Storage: It features cost-effectiveness and large capacity, making it suitable for scenarios such as data backup, file sharing, and log storage.
      • Performance Storage: It features high throughput and IOPS, making it suitable for IO-intensive workloads such as high-performance computing, media asset rendering, machine learning, DevOps, and OA.
      File service protocol It is **NFS** by default to allow for pass-through access to files and file systems on the server.
      Protocol version We recommend you use NFSv3 for better performance. If your application relies on file locking (that is, multiple CVM instances are needed to edit a file), use NFSv4 for mounting.
      Permission group Configure a permission group for the file system, which is used to manage the access and read/write permissions of clients that access the file system on the same network. Select a permission group as needed. If no such permission group is available, create one on the Permission Group page.
      Reclaim policy It can be Delete or Retain. The latter is recommended out of data security considerations.
      • Delete: If a PV is dynamically created through a PVC, the PV and storage instance bound to the PVC will be automatically terminated when the PVC is terminated.
      • Retain: If a PV is dynamically created through a PVC, the PV and storage instance bound to the PVC will be retained when the PVC is terminated.
      Tag Select the cloud tag to be bound to the CFS instance. The tag will be automatically inherited by the CFS instance that is created dynamically by a StorageClass. After a StorageClass is created, the parameters of the bound tag cannot be modified. If the existing tags are not suitable, create one in the Tag console.
    5. Click Create StorageClass to complete the process.

    Creating a PVC by using the specified StorageClass

    1. On the Cluster management page, select the ID of the cluster for which a PVC needs to be created.
    2. On the cluster details page, select Storage > PersistentVolumeClaim on the left sidebar.
    3. Click Create to enter the Create PersistentVolumeClaim page and configure key parameters of the PVC.
      Configuration Item Description
      Name Enter the `PersistentVolumeClaim` name, for example, `cfs-pvc`.
      Namespace A namespace is used to assign cluster resources. Here, default is selected.
      Provisioner Select Cloud File Storage.
      R/W permission CFS only supports **Multi-computer read and write**.
      StorageClass Specify the StorageClass as needed. Here, Specify is selected. `cfs-storageclass` created in the Creating a StorageClass step is used as an example.
      Note
      • The PVC and PV will be bound to the same StorageClass.
      • If you select Do not specify, the value of `StorageClass` for the corresponding PVC is empty, and the value of the `storageClassName` field in the corresponding YAML file is an empty string.
      PersistentVolume Specify the PersistentVolume as needed. Here, Do not specify is selected.
      Note
      • The system first searches the current cluster for PVs that meet the binding rules. If there is no such PV, the system dynamically creates a PV to be bound based on the PVC and StorageClass.
      • Either StorageClass or PersistVolume should be specified.
      • For more information on Do not specify for PersistentVolume, see PV and PVC binding rules.
    4. Click Create PersistentVolumeClaim.

    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. For detailed directions, see Deployment Management. Then, mount a volume based on the following information.
    • Volume (optional):
      • Mount method: Select Use existing PVC.
      • Volume name: Set a custom name. This document uses cfs-vol as an example.
      • Select PVC: Select cfs-pvc, which you created in the step of Creating a PVC.
    • Containers in the Pod: Click Add mount target to set a mount target.
      • Volume: Select the volume cfs-vol that you added 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.
    1. Click Create Workload to complete the process.
      Note:

      If you use the PVC mount method of CFS, the volume can be mounted to multiple nodes.

    kubectl Operation Guide

    Creating a StorageClass

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
     name: cfs
    parameters:
     # subdir-share: "true" 
     vpcid: vpc-xxxxxxxx
     subnetid: subnet-xxxxxxxx
     vers: "3"
     resourcetags: ""
    provisioner: com.tencent.cloud.csi.cfs
    reclaimPolicy: Delete
    volumeBindingMode: Immediate
    

    The following parameters can be configured:

    Parameter Required Description
    zone No It defines the region of the file storage.
    pgroupid No It defines the permission group for the file storage.
    storagetype No It defaults to Standard Storage (SD). Valid values:
    SD (Standard Storage)
    HP (Performance Storage)
    subdir-share Yes It indicates the shared instance mode for instance creation by StorageClass.
    vpcid Yes It indicates the ID of the VPC where the file is stored.
    subnetid Yes It indicates the ID of the subnet where the file is stored.
    vers Yes It indicates the version of the protocol used by the add-on to connect to the file system. The dynamically created PVs inherit this parameter. The versions "3" and "4" are supported.
    resourcetags Yes It indicates the cloud tag of the file system. A corresponding Tencent Cloud tag is applied on the generated file system. Multiple tags are separated by commas. For example, "a:b,c:d".

    Creating a PVC

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
     name: cfs
     namespace: default
    spec:
     accessModes:
     - ReadWriteMany
     resources:
       requests:
         storage: 10Gi
     storageClassName: cfs
     volumeMode: Filesystem
     volumeName: XXX
    
    Parameter Required Description
    spec.accessModes No The cfs storage supports Multiple-Read-Multiple-Write.
    spec.resources.requests.storage Yes The storage capacity only depends on the type of the file system.
    Note:

    1. CFS supports expanding the storage capacity of the file system according to the file size. The requests and applications are not interrupted during the expansion. The default CFS instance capacity is 10 GiB, and the upper limit of the capacity depends on the product type. For details, see System Restrictions.
    2. The PVs dynamically created through a PVC inherit the parameters configured in StorageClass. The parameters are generated automatically by the storage add-on.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support