Volume Management

Last updated: 2020-05-06 11:14:47

    Introduction

    Volume types

    Volume TypeDescription
    Use temporary path /
    Use node path Mount the file directory of the host where the container resides to the path specified by the container (corresponding to HostPath in Kubernetes). You can also choose not to set the source path (corresponding to EmptyDir in Kubernetes). If the source path is not specified, the system mounts the temporary directory of the assigned host to the mount target of the container.Local disk volumes that have specified source paths are suitable for persisting data to the host where the container resides, whereas EmptyDir is suitable for temporary storage for containers.
    Use NFS disk Simply enter the NFS path. You can use Tencent Cloud's Cloud File Storage (CFS) or user-built NFS file storage. An NFS volume is suitable for persistent storage with frequent reads and writes in scenarios such as big data analysis, media processing, and content management.
    Use existing PersistentVolumeClaim Use the storage of the existing PersistentVolumeClaim to declare the storage for workloads, and automatically assign or create a PersistentVolume and mount it to the corresponding pod. This is suitable for stateful applications created by StatefulSet. For more information, see PV and PVC Management.
    Use Tencent Cloud CBS Use the Kubernetes block storage plug-in extended by Tencent Cloud based on CBS. You can mount a Tencent Cloud CBS disk to a specified path of the container. When the container is migrated, the cloud disk will also be migrated.CBS volumes are suitable for the persistent storage of data and can be used for stateful services such as MySQL. Services that are configured with CBS volumes can have a maximum of 1 pod.
    Use ConfigMap A ConfigMap is mounted to a pod as a file system. You can mount the ConfigMap entries to a specific path. For more information, see ConfigMap Management.
    Use Secret A Secret is mounted to a pod as a file system. You can mount Secret entries to a specific path. For more information, see Secret Management.

    Notes on volumes

    • After creating a volume, you need to set the mount point of the container in the "Containers in the Pod" module.
    • Under the same service, the name of the volume and the set mount point must be unique.
    • When the source path of a local disk volume is not specified, the system assigns a temporary directory named /var/lib/kubelet/pods/pod_name/volumes/kubernetes.io~empty-dir, and the lifecycle of the volume with the temporary directory is the same as that of the pod.
    • If no permission is set for volume mounting, the default permission is read/write.

    Operation Guide for Volumes in the Console

    Configurations for mounting different volumes

    Add volumes and set mount points as instructed below.

    Volume Mount Point
    Type Name Others Destination Path Sub-path Read and Write Permissions
    Temporary pathCustom/Specify this path as needed, for example, /cache. Mount only the sub-path or a single file in the selected volume, for example, /data or /test.txt. Select as needed.
  • Read-only: the container path volume can only be read and data modifications must be performed on the host.
  • Read and write: data can be read from and modifications can be saved to the container path volume.
  • Node pathSet the node path.
  • Node Path: the node path cannot be empty. For example, if the container needs to access Docker, the node path can be set to /var/lib/docker.
  • Check Type: TKE provides many check types such as NoChecks and DirectoryOrCreate. Read the description of each type in the console and select a check type as needed.
  • NFS diskNFS Path: enter the CFS address or user-built NFS address.
  • To create a file system, see Creating File Systems and Mount Targets.
  • 10.0.0.161:/ is an example NFS path. To obtain the NFS path, please log in to the CFS console, click the ID of the target file system and find it in **Mount under Linux** on the **Mount Target Info** tab.
  • Existing PVCChoose a PVC as needed.
    Tencent Cloud CBSSelect a cloud disk as needed.
    ConfigMap
  • Select a ConfigMap: select a ConfigMap as needed.
  • Options: **All** and **Specific keys**.
  • Items: if you select **Specific keys**, you can mount it to a specific path by adding items. For example, if the mount point is /data/config and the sub-path is dev, the data will be stored under /data/config/dev.
  • Secret

    Creating a workload to mount a volume

    1. Log in to the TKE console and click Clusters in the left sidebar.
    2. On the Cluster Management page, click the ID of the cluster where you want to deploy a workload to go to the cluster management page.
    3. Under Workload, select a workload type to go to the corresponding information page.
      For example, choose Workload > DaemonSet to go to the DaemonSet page, as shown below:
    4. Click Create to go to the Create a workload page.
    5. Set the workload name, namespace, and other information as instructed. In Volume, click Add Volume.
    6. Select a storage method for the volume. Use Tencent Cloud CBS is selected in this case.
    7. Configure the mount point in Mount Point under Containers in the pod, as shown below:
    8. Set other options as needed and click Create Workload to finish the creation.

    Using kubectl to Manipulate Volumes

    The following is for example only. You can perform creation directly by using kubectl.

    Sample YAML file for mounting a volume to a pod

    apiVersion: v1
    kind: Pod
    metadata:
      name: test-pd
    spec:
      containers:
      - image: k8s.gcr.io/test-webserver
        name: test-container
        volumeMounts:
        - mountPath: /cache
          name: cache-volume
      volumes:
      - name: cache-volume
        emptyDir: {}
    • spec.volumes: set the name, type, and other parameters of the volume
      • spec.volumes.emptyDir: set the temporary path
      • spec.volumes.hostPath: set the host path
      • spec.volumes.nfs: set the NFS disk
      • spec.volumes.persistentVolumeClaim: set the existing PersistentVolumeClaim
    • spec.volumeClaimTemplates: if this declaration is used, PersistentVolumeClaim and PersistentVolume will be automatically created based on the content of the declaration
    • spec.containers.volumeMounts: enter the mount target of the volume

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help