All Products
Search
Document Center

Enterprise Distributed Application Service:Configure environment variables

Last Updated:Nov 28, 2023

You must configure environment variables to run an application in the system. For example, the commands of a Java application can be run only after the JAVA_HOME and PATH environment variables are configured. This topic describes how to configure environment variables for applications in the Enterprise Distributed Application Service (EDAS) console.

Background information

The EDAS console allows you to configure the following three types of environment variables:
  • Custom environment variables: the environment variables that you customize when you create an application.
  • ConfigMaps: the predefined configurations that do not need to be kept confidential. If you want to apply a ConfigMap to an application, the application must be in the same region, cluster, and Kubernetes namespace as the ConfigMap. Otherwise, the application cannot use the ConfigMap.

    For more information about how to create a ConfigMap, see Create a configuration item.

  • Secrets: the predefined configurations, such as passwords and certificates, that need to be kept confidential. If you want to apply a secret to an application, the application must be in the same region, cluster, and Kubernetes namespace as the secret. Otherwise, the application cannot use the secret.

    For more information about how to create a secret, see Create a Secret.

Configure environment variables when you create an application

  1. Log on to the EDAS console.

  2. Log on to the EDAS console. In the left-side navigation pane, choose Application Management > Applications. The Applications page appears. In the top navigation bar, select a region. In the upper part of the page, select a namespace. In the upper-left corner, click Create Application.

  3. In the Basic Information step, specify Cluster Type and Application Runtime Environment and click Next. The following table describes the parameters.

    Parameter

    Description

    Cluster Type

    The type of the cluster in which you want to deploy the application. Select Kubernetes Clusters.

    Application Runtime Environment

    The application runtime environment. Select an application runtime environment based on the type of the hosted application.

    • Java

      • Custom: Select this option if you want to use a custom image to deploy the application in a Kubernetes cluster.

      • Java: Select this option if you want to use a universal JAR package to deploy the application as a Dubbo or a Spring Boot application. You can set the Java Environment parameter after you select this option.

      • Tomcat: Select this option if you want to use a universal WAR package to deploy the application as a Dubbo or a Spring application. You can set the Java Environment and Container Version parameters after you select this option.

      • EDAS-Container (HSF): Select this option if you want to use a WAR or FatJar package to deploy the application as a High-speed Service Framework (HSF) application. You can set the Java Environment, Pandora Version, and Ali-Tomcat Version parameters after you select this option.

    • PHP: Select this option if the application is a PHP application that runs on Apache HTTP Server.

    • Node.js, C++, Go, and Other Languages: Select this option if you want to use a custom image to deploy the application in a Kubernetes cluster. The configuration process for multi-language applications is not described in this topic.

  4. In the Configurations step, configure the environment information, basic information, and deployment method for the application, set the related resource parameters, and then click Next.

  5. In the Advanced Settings step, click Environment Variables and configure environment variables as needed.
    When you create the application, pass the environment variables that you configure to the container to be generated. This way, you do not need to repeatedly add frequently used environment variables. EDAS allows you to customize environment variables and configure environment variables by using ConfigMaps and secrets. EDAS also allows you to add one or more environment variables at a time. Select a method as needed.
    • Add an environment variable at a time.
      • Customize an environment variable. Custom - Environment variable 1
        Note
        • If you want to specify parameters for the Java virtual machine (JVM) heap memory, JVM properties, and Java agent, add the parameters in this step:
          • Variable Name: CATALINA_OPTS
          • Variable Value: [Parameter to be added] $(EDAS_CATALINA_OPTS)
        • If you are using a MySQL image, you can configure the following environment variables:
          • MYSQL_ROOT_PASSWORD: required. Allows you to set a MySQL root password.
          • MYSQL_USER and MYSQL_PASSWORD: optional. Allow you to create an account in addition to the root account and set a password.
          • MYSQL_DATABASE: optional. Allows you to specify the database that you want to create when the container is generated.
        • If you are using another type of image, configure the environment variables as needed.
      • Use a ConfigMap to configure an environment variable.

        Select a ConfigMap from the Variable Value/Variable Reference drop-down list. A ConfigMap may contain multiple key-value pairs. Select a key-value pair as needed.

      • Use a secret to configure an environment variable.

        Select a secret from the Variable Value/Variable Reference drop-down list. A secret may contain multiple key-value pairs. Select a key-value pair as needed.

    • Add multiple environment variables
      ParameterDescription
      TypeThe type of the environment variable. Select Configuration Items or Secret as needed. Custom is not supported. In this example, select Configuration Items.
      Configuration ModeThe mode in which environment variables are configured. Valid values: env and envFrom.
      • env: After you select a ConfigMap, you must also select the key-value pairs in the ConfigMap.
      • envFrom: After you select a ConfigMap, you cannot select the key-value pairs in the ConfigMap. By default, all key-value pairs are selected.
      Note
      • You can add a maximum of 100 environment variables at a time.
      • You can use a YAML file to import key-value pairs when you create a ConfigMap in envFrom mode. However, if you use a ConfigMap to configure environment variables in the console, these key-value pairs are not displayed.
      Configuration ItemsSelect a ConfigMap from the drop-down list.
      Reference Environment VariableSelect the key-value pairs that you want to configure in env mode.
      Note After environment variables are added, you must set the names of the environment variables based on your needs.
  6. Click Create Application.

  7. On the Creation Completed page, check the information in the Basic Information, Configurations, and Advanced Settings sections. Then, click Create Application.

    In the upper part of the Application Overview page, click View Details. On the Change List page, view the application change process. Wait several minutes until the application is deployed. After the application change process is complete, view the status of the instance in the Basic Information section of the Application Overview page. If the status shows that a pod is running, the application is deployed.

Configure environment variables when you update an application

If you do not configure environment variables when you create an application, you can configure them when you deploy the application.

  1. Log on to the EDAS console.

  2. In the left-side navigation pane, click Application Management > Applications. In the top navigation bar, select a region. In the upper part of the page, select a namespace. Select Container Service or Serverless Kubernetes Cluster from the Cluster Type drop-down list. Then, find the application that you want to deploy and click the application name.

  3. On the Overview or Basic information page, choose Deploy > Deploy in the upper-right corner.

  4. On the Select Deployment Mode page, select a deployment mode and click Start Deployment in the upper-right corner of the specified deployment mode section.

  5. Set the runtime environment and deployment package for the application, click Environment Variables, complete the configuration as needed, and then click OK.
    When you create the application, pass the environment variables that you configure to the container to be generated. This way, you do not need to repeatedly add frequently used environment variables. EDAS allows you to customize environment variables and configure environment variables by using ConfigMaps and secrets. EDAS also allows you to add one or more environment variables at a time. Select a method as needed.
    • Add an environment variable at a time.
      • Customize an environment variable. Custom - Environment variable 1
        Note
        • If you want to specify parameters for the Java virtual machine (JVM) heap memory, JVM properties, and Java agent, add the parameters in this step:
          • Variable Name: CATALINA_OPTS
          • Variable Value: [Parameter to be added] $(EDAS_CATALINA_OPTS)
        • If you are using a MySQL image, you can configure the following environment variables:
          • MYSQL_ROOT_PASSWORD: required. Allows you to set a MySQL root password.
          • MYSQL_USER and MYSQL_PASSWORD: optional. Allow you to create an account in addition to the root account and set a password.
          • MYSQL_DATABASE: optional. Allows you to specify the database that you want to create when the container is generated.
        • If you are using another type of image, configure the environment variables as needed.
      • Use a ConfigMap to configure an environment variable.

        Select a ConfigMap from the Variable Value/Variable Reference drop-down list. A ConfigMap may contain multiple key-value pairs. Select a key-value pair as needed.

      • Use a secret to configure an environment variable.

        Select a secret from the Variable Value/Variable Reference drop-down list. A secret may contain multiple key-value pairs. Select a key-value pair as needed.

    • Add multiple environment variables
      ParameterDescription
      TypeThe type of the environment variable. Select Configuration Items or Secret as needed. Custom is not supported. In this example, select Configuration Items.
      Configuration ModeThe mode in which environment variables are configured. Valid values: env and envFrom.
      • env: After you select a ConfigMap, you must also select the key-value pairs in the ConfigMap.
      • envFrom: After you select a ConfigMap, you cannot select the key-value pairs in the ConfigMap. By default, all key-value pairs are selected.
      Note
      • You can add a maximum of 100 environment variables at a time.
      • You can use a YAML file to import key-value pairs when you create a ConfigMap in envFrom mode. However, if you use a ConfigMap to configure environment variables in the console, these key-value pairs are not displayed.
      Configuration ItemsSelect a ConfigMap from the drop-down list.
      Reference Environment VariableSelect the key-value pairs that you want to configure in env mode.
      Note After environment variables are added, you must set the names of the environment variables based on your needs.
    Important The application is restarted after you click OK. We recommend that you configure environment variables during off-peak hours.

Verify the result

  • Method 1

    In the left-side navigation pane of the application details page, click Change Records to view the change details of the application. If the value in the Change Status column is Success, the application is deployed and the configuration takes effect.

  • Method 2

    On the Application Overview page, click Running Pods (Click View) next to Running Status. In the Pod section of the App Configurations panel, check the Status column of the pod. If a green dot appears, the application is in the running state. This means that the application is deployed as expected and the configuration takes effect.