Configure environment variables

更新时间:
复制 MD 格式

Applications require specific environment variables to run. For example, a Java application requires the JAVA_HOME and Path variables to be configured before it can run. This topic describes how to configure environment variables for an application in the SAE console. You can set custom environment variables or reference variables from ConfigMaps and Secrets within a namespace.

Procedure

  1. The entry point varies depending on the scenario:

    Create an application

    1. Log on to the SAE console. In the left-side navigation pane, choose Application Management > Applications. Select a region and namespace, then click Create Application.

    2. On the Basic Information page, configure the settings and click Next: Advanced Settings.

    Deploy 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.

    1. Log on to the SAE console. In the left-side navigation pane, choose Application Management > Applications. Select a region and namespace, then click the application name.

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

    Modify application

    1. Log on to the SAE console. In the left-side navigation pane, choose Application Management > Applications. Select a region and namespace, then click the application name.

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

  2. Expand the Environment Variable section and configure your variables.

Configuration

Add a custom environment variable

From the Type drop-down list, select Custom. Enter a Variable Name and a Variable Value.

Reference a ConfigMap

From the Type drop-down list, select Reference ConfigMap. Enter a Variable Name. From the ConfigMap Name, Key drop-down list, select a ConfigMap and a key. You can reference a single key or All Keys.

You can create ConfigMaps in advance on the Namespace page. Alternatively, click Create Configuration Item (ConfigMap) in the current section to create one in the Create ConfigMap panel. For more information, see Manage and use ConfigMaps (Kubernetes ConfigMap).

Note
  • If you select All Keys, SAE uses the key names from the ConfigMap as the environment variable names. These names cannot be changed.

  • Keep environment variable names under 256 characters.

Reference a Secret

From the Type drop-down list, select Reference the Secret. Enter a Variable Name. From the Secret Name, Key drop-down list, select a Secret and a key. You can reference a single key or All Keys.

You can create Secrets in advance on the Namespace page. Alternatively, click Create Secret in the current section to create one in the Create Secret panel. For more information, see Manage and use Secrets (Kubernetes Secret).

Note
  • If you select All Keys, SAE uses the key names from the Secret as the environment variable names. These names cannot be changed.

  • Keep environment variable names under 256 characters.

Example

If your application uses MySQL, configure these environment variables during deployment:

  • Required: MYSQL_ROOT_PASSWORD: Sets the MySQL root password. The MySQL container will not start if this variable is not set.

  • Optional: MYSQL_USER and MYSQL_PASSWORD: Creates a new user and its password.

  • Optional: MYSQL_DATABASE: Creates a new database when the container starts.