Updated on 2024-06-17 GMT+08:00

Mounting a Local Volume

Scenarios

There are four types of local volumes:

  • hostPath: mounts a file directory of the host where the container is located to the specified mount point of the container. For example, if the container needs to access /etc/hosts, you can use hostPath volume to map /etc/hosts.
  • emptyDir: applies to temporary data storage, disaster recovery, and runtime data sharing. It will be deleted upon deletion or transfer of workload pods. The lifecycle is the same as that of the container pod. When the pod is deleted, the emptyDir volume is deleted and its data is lost.
  • ConfigMap: After you mount a ConfigMap to a container, you can read the ConfigMap data from the mount path of the container.
  • Secret: After you mount a secret to a container, you can read the secret data from the mount path of the container.

HostPath

HostPath is a path for mounting a file or directory from a host's file system into a container. Such a volume is usually used to store containerized application logs that need to be stored permanently or containerized applications that need to access internal data structure of the Docker engine on the host.

  1. Set the basic container information by referring to Creating a Deployment, Creating a StatefulSet, or Creating a DaemonSet. After setting the basic container information, click Data Storage. On the Local Volumes tab page, click .

    Figure 1 Container storage configuration

  2. Set parameters for adding a local volume, as listed in Table 1.

    Table 1 HostPath parameters

    Parameter

    Description

    Volume Type

    Select hostPath.

    hostPath

    Path on the host, for example, /etc/hosts.

    Mount Path

    Container path to which the data volume will be mounted.

    NOTICE:
    • The container path cannot be a system directory, such as / or /var/run. Otherwise, the container may not function normally. Select an empty directory. If the directory is not empty, ensure that the directory does not contain any files that affect container startup. Otherwise, the files will be replaced, and the container cannot start normally. As a result, the application may not be created.
    • If a volume is mounted to a high-risk directory, use an account with minimum permissions to start the container. Otherwise, high-risk files on the host may be damaged.

    Subpath

    A subpath is used to mount a local volume so that the same data volume is used in a single pod. If this parameter is left blank, the root path is used.

    Permissions

    • Read-only: You can only read the data in the mounted volume.
    • Read-write: You can modify the volume mounted to the path. Newly written data will not be migrated if the container is migrated, which may cause data loss.

  3. You can add multiple settings. Click OK to complete the configuration.

emptyDir

emptyDir applies to temporary data storage, disaster recovery, and runtime data sharing. It will be deleted upon deletion or transfer of workload pods.

  1. Set the basic container information by referring to Creating a Deployment, Creating a StatefulSet, or Creating a DaemonSet. After setting the basic container information, click Data Storage. On the Local Volumes tab page, click .

    Figure 2 Container storage configuration

  2. Set parameters for adding a local volume, as listed in Table 2.

    Table 2 emptyDir parameters

    Parameter

    Description

    Volume Type

    Select emptyDir.

    Medium

    • Default: Data is stored in disks. This approach is used when there is a large amount of data, with low requirements on reading and writing efficiency.
    • Memory: You can select this option to improve the running speed, but the storage capacity is subject to the memory size. This mode applies to a small amount of data with high requirements on reading and writing efficiency.

    Mount Path

    Container path to which the data volume will be mounted.

    NOTICE:
    • The container path cannot be a system directory, such as / or /var/run. Otherwise, the container may not function normally. Select an empty directory. If the directory is not empty, ensure that the directory does not contain any files that affect container startup. Otherwise, the files will be replaced, and the container cannot start normally. As a result, the application may not be created.
    • If a volume is mounted to a high-risk directory, use an account with minimum permissions to start the container. Otherwise, high-risk files on the host may be damaged.

    Subpath

    A subpath is used to mount a local volume so that the same data volume is used in a single pod. If this parameter is left blank, the root path is used.

    Permissions

    • Read-only: You can only read the data in the mounted volume.
    • Read-write: You can modify the volume mounted to the path. Newly written data will not be migrated if the container is migrated, which may cause data loss.

  3. You can add multiple settings. Click OK to complete the configuration.

ConfigMap

ConfigMap is used to process workload configuration parameters. Before that, you need to create ConfigMaps. For details, see ConfigMaps.

  1. Set the basic container information by referring to Creating a Deployment, Creating a StatefulSet, or Creating a DaemonSet. After setting the basic container information, click Data Storage. On the Local Volumes tab page, click .

    Figure 3 Container storage configuration

  2. Set parameters for adding a local volume, as listed in Table 3.

    Table 3 ConfigMap parameters

    Parameter

    Description

    Storage Type

    Select ConfigMap.

    ConfigMap

    Select the desired ConfigMap name.
    NOTE:

    A ConfigMap must be created in advance. For details, see ConfigMaps.

    Mount Path

    Container path to which the data volume will be mounted.

    NOTICE:
    • The container path cannot be a system directory, such as / or /var/run. Otherwise, the container may not function normally. Select an empty directory. If the directory is not empty, ensure that the directory does not contain any files that affect container startup. Otherwise, the files will be replaced, and the container cannot start normally. As a result, the application may not be created.
    • If a volume is mounted to a high-risk directory, use an account with minimum permissions to start the container. Otherwise, high-risk files on the host may be damaged.

    Subpath

    A subpath is used to mount a local volume so that the same data volume is used in a single pod. If this parameter is left blank, the root path is used.

    Permissions

    Only Read-only is supported. You can only read the file system in the container path.

  3. You can add multiple settings. Click OK to complete the configuration.

Secret

Mount the data in the secret to the specified container. The content of the secret is user-defined. Before that, you need to create a secret. For details, see Secrets.

  1. Set the basic container information by referring to Creating a Deployment, Creating a StatefulSet, or Creating a DaemonSet. After setting the basic container information, click Data Storage. On the Local Volumes tab page, click .

    Figure 4 Container storage configuration

  2. Set parameters for adding a local volume, as listed in Table 4.

    Table 4 Secret parameters

    Parameter

    Description

    Volume Type

    Select Secret.

    Secrets

    Select the desired secret name.
    NOTE:

    A secret must be created in advance. For details, see Secrets.

    Mount Path

    Container path to which the data volume will be mounted.

    NOTICE:
    • The container path cannot be a system directory, such as / or /var/run. Otherwise, the container may not function normally. Select an empty directory. If the directory is not empty, ensure that the directory does not contain any files that affect container startup. Otherwise, the files will be replaced, and the container cannot start normally. As a result, the application may not be created.
    • If a volume is mounted to a high-risk directory, use an account with minimum permissions to start the container. Otherwise, high-risk files on the host may be damaged.

    Subpath

    A subpath is used to mount a local volume so that the same data volume is used in a single pod. If this parameter is left blank, the root path is used.

    Permissions

    Only Read-only is supported. You can only read the file system in the container path.

  3. You can add multiple settings. Click OK to complete the configuration.