Volume Management

Last updated: 2020-02-25 10:04:59

PDF

Overview

Volume Types

Volume typeDescription
Use node pathMount the file Directory of the host where the container resides to the specified path of the container (that is, the HostPath corresponding to Kubernetes). You can choose not to set the source path (corresponding to EmptyDir in Kubernetes) based on your business needs. If the source path is not set, the system mounts the temporary Directory of Assign host to the mount point of the container.Volume, the local hard disk of the specified source path, is suitable for persistent storage of data to the host where the container resides, and EmptyDir is suitable for temporary storage of the container.
Use NFS diskNFS disk: Simply enter the NFS path. Just need Enter NFS path, you can use Tencent Cloud's File storage CFS You can also use Client's 's file to store NFS.An NFS volume is well suited for persistent storage with frequent reads and writes and scenarios such as big data analytics, media processing, and content management.
Use existing PersistentVolumeClaimUse the storage of the existing PersistentVolumeClaim declared workload to automatically mount Assign or Create PersistentVolume to the corresponding Pod. This is mainly well suited for stateful applications created by StatefulSets. For more details, seePV and PVC Management.
Use the new PersistentVolumeClaimCreate declares the storage of a PersistentVolumeClaim workload, and Assign or Create PersistentVolume is automatically mounted to the corresponding Pod. This is mainly well suited for stateful applications created by StatefulSets. For more details, seePV and PVC Management.
Use Tencent Cloud CBSTencent Cloud is a block storage plug-in based on Kubernetes extended by CBS. You can specify a piece of Tencent Cloud's CBS HDD cloud disk to be mounted to a certain path of the container. When the container migrates, HDD cloud disk will migrate with it.Using HDD cloud disk and volume is suitable for persistent storage of data, and can be used for stateful services such as Mysql. Set the service of HDD cloud disk and volume. The maximum number of instances is 1.
Using ConfigMapConfigMap is mounted to Pod in the form of a file system, and custom ConfigMap entries can be mounted to a specific path. For more details, seeConfigMap management.
Using SecretSecret is mounted to Pod in the form of a file system, and custom Secret entries can be mounted to a specific path. For more details, seeSecret Management.

Notes on Volumes

  • After creating volume, you need to set the mount point of the container in the "containers in instance" module.
  • Under the same service, the name of the volume and the mount point set for the container must be unique.
  • When the source path of a local disk volume is empty, the system will assign a temporary directory /var/lib/kubelet/pods/pod_name/volumes/kubernetes.io~empty-dir , and the volume using the temporary directory is the same as that of the Pod.
  • If no permission is set for volume mount, the default setting will be read/write permission.

Operation Guide for Volumes in the Console

Creating a Workload to Mount a 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.
    For example, select 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 As shown below:
  6. According to the actual demand, choose the storage mode of volume. This paper takes [using Tencent Cloud hard disk] as an example.
  7. Configure the mount point in the mount point of the container in the instance.
  8. Please set the remaining options as needed, and click "create Workload" to complete the creation.

Using kubectl to Manipulate Volumes

The following is a sample where which you can perform creation directly using kubectl.

Sample YAML 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 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.
  • spec.containers.volumeMounts: Enter the mount point of the volume.