All Products
Search
Document Center

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

Last Updated:Aug 12, 2026

ConfigMaps serve as environment variables or mounted configuration files in application containers, enabling you to change configurations after deployment without rebuilding the image.

SAE environment variables take effect only during the instance runtime phase. Environment variable injection is not supported during the build phase. As a deployment attribute of the application, environment variables are injected into the runtime environment when the container starts and are not involved in the image build process.

To dynamically fetch configuration data from a configuration center, see Use Nacos in MSE or Manage distributed configurations (ACM).

To store sensitive information, such as keys and certificates, see Manage and use Secrets (K8s Secret).

Create a ConfigMap

  1. On the SAE ConfigMaps page, select the region and namespace for your application, and then click Create.

    1. Specify a custom ConfigMap Name.

    2. Under Configure Mappings, select an editing mode to define the key-value pairs:

      • Edit using form: Click Add Variable, and then enter a key and its value. You can add multiple key-value pairs. For long configuration content, click the image icon next to the value to paste and edit the value in a larger editor.

      • Edit in JSON format: In the code editor, enter one or more key-value pairs. Keys and string values must be enclosed in double quotes (""). 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    }"
        }
        
      • Edit in YAML format: In the code editor, enter one or more key-value pairs. For example:

        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. Find the ConfigMap you created in the Configuration Item (ConfigMap) list. You can then Edit, Copy, View Record, or Delete it.

    Important

Use a ConfigMap as an environment variable

  1. Create an application

    On the SAE Application List page, select a destination region and namespace in the top navigation bar, and then click Create Application. On the Application Basic Information page, configure the parameters and click Next: Advanced Settings.

    Change a running application

    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.

    On the SAE Application List page, select a destination region and namespace in the top navigation bar. Click the ID of the target Application to open the application details page.In the navigation pane on the left, click Basic Information. In the upper-right corner, click Deploy Application.

    Change a stopped application

    On the SAE Application List page, select a destination region and namespace in the top navigation bar. Click the ID of the target Application to open the application details page.Click Basic Information, and then click Modify Application Configuration.

  1. In the Environment Variable section, set Type to Reference ConfigMap. Specify a custom Variable Name for the environment variable in your application, and then select the ConfigMap Name and Key to reference. You can add multiple variables. If you choose to reference all keys from the ConfigMap, you do not need to specify a Variable Name, as the original key names are used as the environment variable names.

  2. Wait for the application to deploy. To verify the configuration, log on to the web shell of the application instance and run the command env | grep <variable_name>. Replace <variable_name> with the variable name you configured. If the output shows the correct variable name and value, the configuration is successful.

Mount a ConfigMap as a file

Mounting a ConfigMap as a file writes the value of the specified key as the file content. You can customize the file path and name. The mounted file overwrites any existing file at the same path.

Use this approach to manage configuration files without rebuilding the container image. To modify an existing configuration file, copy its content into a ConfigMap value, then mount the ConfigMap to the original file path.

  1. Create an application

    On the SAE Application List page, select a destination region and namespace in the top navigation bar, and then click Create Application. On the Application Basic Information page, configure the parameters and click Next: Advanced Settings.

    Change a running application

    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.

    On the SAE Application List page, select a destination region and namespace in the top navigation bar. Click the ID of the target Application to open the application details page.In the navigation pane on the left, click Basic Information. In the upper-right corner, click Deploy Application.

    Change a stopped application

    On the SAE Application List page, select a destination region and namespace in the top navigation bar. Click the ID of the target Application to open the application details page.Click Basic Information, and then click Modify Application Configuration.

  1. In the Configuration Management section, click + Add. Select the ConfigMap Name and the Key to mount (or choose to mount all keys). Then, specify the Mount Path. If you are mounting a single key, provide an absolute path including the filename. If you are mounting all keys, provide an absolute path to a directory, and SAE automatically uses the key names as filenames. You can add multiple mounts.

  2. Wait for the application to deploy. To verify the configuration, log on to the web shell of the application instance and check the content of the file at the mount path.

Examples

Configure php-fpm.conf

  1. Create a ConfigMap.

    1. Set ConfigMap Name to php-fpm.

    2. For Configure Mappings, select Edit in YAML format and enter the following configuration:

      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 your PHP application.

    1. Set ConfigMap Name to php-fpm.

    2. Set Key to www_conf.

    3. The mount path is /usr/local/etc/php-fpm.d/www.conf.