All Products
Search
Document Center

Serverless App Engine:Manage and use ConfigMaps (K8s ConfigMaps)

Last Updated:Sep 11, 2025

A ConfigMap (Kubernetes ConfigMap) can be used as an environment variable for an application runtime or mounted as a configuration file to an application container's file system. Using a ConfigMap lets you change configurations after application deployment without rebuilding the image.

This topic does not apply to scenarios where you need to dynamically obtain configuration information from a configuration center. For more information, see Use Nacos in MSE or Manage distributed configurations (ACM).

To store sensitive information, such as keys and certificates, see Managing and using K8s Secrets.

Create a ConfigMap

  1. On the SAE ConfigMaps page, select the destination region and namespace at the top of the page, and then click Create. Ensure that you select the namespace where the target application is located.

    1. Specify a custom Configuration Item Name.

    2. Configuration Mapping: Select an edit mode and configure the variable name and value mappings.

      • Edit With Form: Click Add Variable and enter the variable name and its value. You can add multiple variables. For long configuration content, you can click the image icon next to the variable value to paste and edit the content.

      • Edit In JSON Format: In the code box, enter one or more mappings of variable names and their values. The variable names and values must be enclosed in "". For example:

        {
            "nv_shell": "/bin/sh",
            "nginx_conf": "daemon            off;\nworker_processes  2;\nuser              www-data;\n\nevents {\n    use           epoll;\n    worker_connections  128;\n}\n\nerror_log         logs/error.log info;\n\nhttp {\n    server_tokens off;\n    include       mime.types;\n    charset       utf-8;\n\n    access_log    logs/access.log  combined;\n\n    server {\n        server_name   localhost;\n        listen        127.0.0.1:80;\n\n        error_page    500 502 503 504  /50x.html;\n\n        location      / {\n            root      html;\n        }\n\n    }"
        }
        
      • Use YAML Format: In the code box, enter one or more mappings of variable names and their values. The following is a sample configuration:

        nv_shell: /bin/sh
        nginx_conf: |-
          daemon            off;
          worker_processes  2;
          user              www-data;
        
          events {
              use           epoll;
              worker_connections  128;
          }
        
          error_log         logs/error.log info;
        
          http {
              server_tokens off;
              include       mime.types;
              charset       utf-8;
        
              access_log    logs/access.log  combined;
        
              server {
                  server_name   localhost;
                  listen        127.0.0.1:80;
        
                  error_page    500 502 503 504  /50x.html;
        
                  location      / {
                      root      html;
                  }
        
              }
  2. In the ConfigMap list, you can view the created ConfigMaps and perform operations such as Edit, Copy, View History, and Delete.

    Important

Use a ConfigMap as an environment variable for an application

  1. Create an application

    1. Log on to the SAE console. In the left-side navigation pane, choose Applications > Applications. On the page that appears, select a region in the top navigation bar and a namespace from the Namespace drop-down list, and then click Create Application.

    2. After the Basic Information is specified on Create Application page, click Next: Advanced Settings.

    Modify running applications

    Warning

    After you redeploy an application, the application is restarted. To prevent unpredictable errors such as business interruptions, we recommend that you deploy applications during off-peak hours.

    1. Log on to the SAE console. In the left-side navigation pane, choose Applications > Applications. On the page that appears, select a region in the top navigation bar and a namespace from the Namespace drop-down list, and then click the desired application name.

    2. On the Basic Information page of the application, click Deploy Application.

    Modify stopped applications

    1. Log on to the SAE console. In the left-side navigation pane, choose Applications > Applications. On the page that appears, select a region in the top navigation bar and a namespace from the Namespace drop-down list, and then click the desired application name.

    2. On the Basic Information page of the application, click Modify Application Configurations.

  1. In the Environment Variable section, set Type to Reference Configuration Item and specify a custom Variable Name for the current application. If you reference all keys, you do not need to specify a variable name because the key names are used as the variable names. Then, select an existing Configuration Item Name and Key. A key is a variable in the configuration item. Referencing all keys is also supported. You can add multiple configuration items.

  2. Wait for the application to be deployed. To verify that the configuration is effective, log on to the web shell of the application instance and run the env | grep <variable name> command. Replace <variable name> with the variable name that you configured. If the command returns the mapping of the variable name and its value, the configuration is effective.

Mount a ConfigMap as a configuration file to the file system of an application

You can mount a ConfigMap to the file system of an application container. The value of the ConfigMap is used as the file content. You can customize the file path and name. If a file with the same name exists in the path, the mounted file overwrites the original file.

A mounted file is often used as the application's configuration file. This lets you change configurations without rebuilding the image. To modify an existing configuration file in the application container, first copy the original file content to your local machine. After you modify the content, save it as the value of a ConfigMap. Then, follow the instructions in this topic to mount the ConfigMap to the application's file system.

  1. Create an application

    1. Log on to the SAE console. In the left-side navigation pane, choose Applications > Applications. On the page that appears, select a region in the top navigation bar and a namespace from the Namespace drop-down list, and then click Create Application.

    2. After the Basic Information is specified on Create Application page, click Next: Advanced Settings.

    Modify running applications

    Warning

    After you redeploy an application, the application is restarted. To prevent unpredictable errors such as business interruptions, we recommend that you deploy applications during off-peak hours.

    1. Log on to the SAE console. In the left-side navigation pane, choose Applications > Applications. On the page that appears, select a region in the top navigation bar and a namespace from the Namespace drop-down list, and then click the desired application name.

    2. On the Basic Information page of the application, click Deploy Application.

    Modify stopped applications

    1. Log on to the SAE console. In the left-side navigation pane, choose Applications > Applications. On the page that appears, select a region in the top navigation bar and a namespace from the Namespace drop-down list, and then click the desired application name.

    2. On the Basic Information page of the application, click Modify Application Configurations.

  1. In the Configuration Management area, click + Add. Select the Configuration Item Name and Key of an existing configuration item. The key is the variable name in the configuration item. You can mount a single key or all keys. Then, specify a custom Mount Path. To mount a single key, enter an absolute path that includes the filename. To mount all keys, enter an absolute path that does not include a filename. SAE automatically uses the key name of each configuration item as the filename. You can add multiple configuration items.

  2. Wait for the application to be deployed. To verify that the configuration is effective, log on to the web shell of the application instance and view the file content in the mount path.

Scenario examples

Configure php-fpm.conf for a PHP application

  1. Create a ConfigMap.

    1. Set ConfigMap Name to php-fpm.

    2. For Configuration Mapping, select Edit With YAML and enter the following YAML configuration in the code box:

      www_conf: |
        [www]
        user = www-data
        group = www-data
        listen = 127.0.0.1:9000
        pm = dynamic
        pm.max_children = 5
        pm.start_servers = 2
        pm.min_spare_servers = 1
        pm.max_spare_servers = 3
  1. Mount the ConfigMap as a configuration file to the file system of the PHP application that you created.

    1. Set Configuration Item Name to php-fpm.

    2. Set Key to www_conf.

    3. Set the mount path to /usr/local/etc/php-fpm.d/www.conf.

Configure nginx.conf for Nginx

For more information, see Deploy an Nginx service using SAE.