Updated on 2022-04-02 GMT+08:00

Creating a ConfigMap

A ConfigMap is a type of resource that stores configuration information required by a workload. Its content is user-defined. After creating ConfigMaps, you can use them as files or environment variables in a workload.

ConfigMaps allow you to decouple configuration files from container images to enhance the portability of workloads.

ConfigMaps provide the following benefits:

  • Manage configurations for different environments and services.
  • Deploy workloads in different environments. Multiple versions are supported for configuration files so that you can update and roll back workloads easily.
  • Quickly import configurations in the form of files to containers.

Creating a ConfigMap

  1. Log in to the cluster console. In the left navigation pane, choose Configuration Center > ConfigMaps. You can create a ConfigMap directly or using YAML. If you want to create a ConfigMap using YAML, go to 3.
  2. Create a ConfigMap directly by clicking Create ConfigMap.

    Set the parameters listed in Table 1. The parameters marked with asterisks (*) are mandatory.
    Table 1 Parameters for creating a ConfigMap

    Parameter

    Description

    *Name

    Name of a ConfigMap, which must be unique in a namespace.

    *Cluster

    Select the cluster for which you want to create a ConfigMap.

    *Namespace

    Namespace to which the ConfigMap belongs. If you do not specify this parameter, the value default is used by default.

    Description

    Description of the ConfigMap.

    Data

    The workload configuration data can be used in a container. Key specifies the file name, and Value specifies the file content.

    1. Click Add Data.
    2. Set Key and Value.

    Label

    Labels are attached to objects such as workloads, nodes, and Services in key-value pairs.

    Labels define identified attributes of these objects and can be used to manage and select objects.

    1. Click Add Label.
    2. Set Key and Value.

  3. Create a ConfigMap using a YAML file by clicking Create Using YAML.

    To create a resource by uploading a file, ensure that the resource description file has been created. MCP supports files in JSON or YAML format. For details, see ConfigMap Resource File Configuration.

    You can import or directly write the file content in YAML or JSON format.
    • Method 1: Import an orchestration file.

      Click Upload YAML File to import a YAML or JSON file. The content of the YAML or JSON file is displayed in the orchestration content area.

    • Method 2: Directly orchestrate the content.

      In the orchestration content area, enter the content of the YAML or JSON file.

  4. Click Create after the configuration is complete.

    The new ConfigMap is displayed in the ConfigMap list.

ConfigMap Resource File Configuration

A ConfigMap resource file can be in JSON or YAML format, and the file size cannot exceed 2 MB.

  • JSON format

    The file name is configmap.json and the configuration example is as follows:

    {
      "kind": "ConfigMap",
      "apiVersion": "v1",
      "metadata": {
        "name": "paas-broker-app-017",
        "namespace": "test"
      },
      "data": {
        "context": "{\"applicationComponent\":{\"properties\":{\"custom_spec\":{}},\"node_name\":\"paas-broker-app\",\"stack_id\":\"0177eae1-89d3-cb8a-1f94-c0feb7e91d7b\"},\"softwareComponents\":[{\"properties\":{\"custom_spec\":{}},\"node_name\":\"paas-broker\",\"stack_id\":\"0177eae1-89d3-cb8a-1f94-c0feb7e91d7b\"}]}"
      }
    }
  • YAML format

    The file name is configmap.yaml and the configuration example is as follows:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: test-configmap
    data:
      data-1: value-1
      data-2: value-2

Related Operations

After creating a ConfigMap, you can perform the operations described in Table 2.
Table 2 Other operations

Operation

Description

Viewing a YAML file

Click View YAML in the row where the target ConfigMap resides to view its YAML file.

Updating a ConfigMap

  1. Click Update in the row where the target ConfigMap resides.
  2. Modify the ConfigMap data according to Table 1.
  3. Click Update.

Deleting a ConfigMap

Click Delete in the row where the target ConfigMap resides.

Delete the ConfigMap as prompted.