• Cloud Container Engine

cce
  1. Help Center
  2. Cloud Container Engine
  3. User Guide 2.0
  4. Storage Management
  5. Using Local Hard Disks

Using Local Hard Disks

Application Scenarios

Local hard disks are applicable to the following scenarios:

  • HostPath: Mount the file directory of the host where a container is located to the specified mounting point of the container. If the container needs to access /etc/hosts, use HostPath to map /etc/hosts.
  • EmptyDir: Used for temporary storage. The lifecycle is the same as that of a container instance. When a container instance disappears, EmptyDir will be deleted and the data will be permanently lost.
  • ConfigMap: Keys in the configuration items of ConfigMap are mapped to a container so that configuration files can be mounted to the specified container directory. For details on how to create ConfigMap, see section Creating a Configuration Item. For details about ConfigMap usage, see section Using a Configuration Item.
  • Secret: Secret data is mounted to a path of the container. A secret is a type of resource that holds sensitive data, such as authentication and key information. All content is user-defined. For details about how to create a secret, see section Creating a Secret. For details about secret usage, see section Using a Secret.

HostPath

The file or directory of the host is mounted to the container. HostPath is used to store containerized application logs that need to be stored permanently, or to store containerized applications that need to access internal data structure of the Docker engine on the host.

  1. Create an application by following the procedure in section Creating a Stateless Application or section Creating a Stateful Application. Choose Data Storage > Local Disks. On the page that is displayed, click Add Local Disk.
  2. Set parameters for adding a local disk, as listed in Table 1.

    Table 1 Volume type set to HostPath

    Parameter

    Description

    Volume Type

    Type of the local disk to be mounted. It is set to HostPath here.

    * Host Path

    Path of the host to which the local volume is to be mounted, for example, /etc/hosts.

    Add Container Path

    1. Click Add Container Path.
    2. Enter the container path to which the data volume is mounted.
      NOTICE:
      • Do not mount a data volume to a system directory such as / or /var/run; otherwise, the container becomes abnormal. You are advised to mount the data volume to 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. As a result, the container cannot be properly started and the application creation will fail.
      • When the data volume is mounted to a high-risk directory, you are advised to use a low-permission account to start the container; otherwise, high-risk files on the host machine may be damaged.
    3. Set permissions.
      • Read-only: only allows you to read data volumes in the container path.
      • Read/Write: allows you to modify the data volumes in the container path. Newly written data will not be migrated during container migration; otherwise, data loss occurs.
    4. Click OK.

EmptyDir

In this scenario, a volume is automatically created when a container is allocated to a node, and the volume is empty by default. In a pod, all containers can read and write the same files in EmptyDir. When the pod is deleted from a node, data in EmptyDir will be deleted permanently. In general, EmptyDir is used for high-speed storage of temporary data.

  1. Create an application by following the procedure in section Creating a Stateless Application or section Creating a Stateful Application. Choose Data Storage > Local Disks. On the page that is displayed, click Add Local Disk.
  2. Set parameters for adding a local disk, as shown in Table 2.

    Table 2 Volume type set to Empty Dir

    Parameter

    Description

    Volume Type

    Type of the local disk to be mounted. It is set to EmptyDir here.

    Storage Media Type

    • Deselect In-memory storage: Data is stored in disks, which is applicable to a large amount of data with low requirements on reading and writing efficiency.
    • Select In-memory storage: Data is stored in memory, which is applicable to a small amount of data with high requirements on reading and writing efficiency.

    Add Container Path

    1. Click Add Container Path.
    2. Enter the container path to which the data volume is mounted.
      NOTICE:
      • Do not mount a data volume to a system directory such as / or /var/run. This action may cause a container error to occur. You are advised to mount the data volume to 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, making it impossible for the container to be properly started. The application creation will fail.
      • When the data volume is mounted to a high-risk directory, you are advised to use a low-permission account to start the container; otherwise, high-risk files on the host machine may be damaged.
    3. Set permissions.
      • Read-only: only allows you to read data volumes in the container path.
      • Read/Write: allows you to modify the data volumes in the container path. To prevent data loss, newly written data will not be migrated during container migration.
    4. Click OK.

ConfigMap

CCE separates the application codes from configuration files. The configMap volume is used to process application configuration parameters. You need to create application configurations in advance. For details, see Creating a Configuration Item.

  1. Create an application by following the procedure in section Creating a Stateless Application or section Creating a Stateful Application. Choose Data Storage > Local Disks. On the page that is displayed, click Add Local Disk.
  2. Set parameters for adding a local disk, as shown in Table 3.

    Table 3 Volume type set to ConfigMap

    Parameter

    Description

    Volume Type

    Type of the local disk to be mounted. It is set to ConfigMap here.

    * ConfigMap

    Select the desired configMap name.
    NOTE:

    ConfigMap must be created in advance. For details, see Creating a Configuration Item to create a configMap.

    Add Container Path

    1. Click Add Container Path.
    2. Enter the container path to which the data volume is mounted.
      NOTICE:
      • Do not mount a data volume to a system directory such as / or /var/run. This action may cause a container error to occur. You are advised to mount the data volume to 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, making it impossible for the container to be properly started. The application creation will fail.
      • When the data volume is mounted to a high-risk directory, you are advised to use a low-permission account to start the container; otherwise, high-risk files on the host machine may be damaged.
    3. Set the permission to Read-only, which indicates that data volumes in the path are read-only.
    4. Click OK.

Secret

Mount the data in the key to the specified container. The content of the key is user-defined. You need to create application configurations in advance. For more information, see Creating a Secret.

  1. Create an application by following the procedure in section Creating a Stateless Application or section Creating a Stateful Application. Choose Data Storage > Local Disks. On the page that is displayed, click Add Local Disk.
  2. Set parameters for adding a local disk, as shown in Table 4.

    Table 4 Volume type set to Secret

    Parameter

    Description

    Volume Type

    Type of the local disk to be mounted. It is set to Secret here.

    * Secret

    Select the desired secret name.

    NOTE:

    Secret must be created in advance. For details, see Creating a Secret to create a Secret.

    Add Container Path

    1. Click Add Container Path.
    2. Enter the container path to which the data volume is mounted.
      NOTICE:
      • Do not mount a data volume to a system directory such as / or /var/run. This action may cause a container error to occur. You are advised to mount the data volume to 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, making it impossible for the container to be properly started. The application creation will fail.
      • When the data volume is mounted to a high-risk directory, you are advised to use a low-permission account to start the container; otherwise, high-risk files on the host machine may be damaged.
    3. Set the permission to Read-only, which indicates that data volumes in the path are read-only.
    4. Click OK.