Setting Environment Variables (EVs) from a ConfigMap or Secret

Set EVs from the Kubernetes ConfigMap

In Kubernetes, you populate environment variables from application configurations or secrets.

Setting Environment Variables from a Kubernetes ConfigMap

Before you create the Kubernetes ConfigMap, you must create a DuploCloud Service.

Create the Kubernetes ConfigMap

  1. In the DuploCloud Portal, navigate to Kubernetes -> Config Maps.

  2. Click Add. The Add Config Map pane displays.

  3. Name the ConfigMap you want to create, such as my-config-map.

  4. Add a Data key/value pair for each file in your ConfigMap, separated by a colon (:). The key is the file name, and the value is the file's contents.

  5. Click Create.

Editing the DuploCloud Service

  1. In the DuploCloud Portal, navigate to Kubernetes -> Services.

  2. Select the Service you want to modify from the Name column.

  3. Click the Actions menu and select Edit.

Configure Environment Variables

You can import the entire ConfigMap as Environment Variables or choose specific keys to import as environment variables.

Import the entire ConfigMap as Environment Variables

The most straightforward approach is to import the entire ConfigMap as environment variables. Using this approach, your service will recognize each key in the ConfigMap defined as an environment variable.

  1. On the Edit Service: service_name Basic Options page, click Next to navigate to the Advanced Options page.

  2. On the Advanced Options page, in the Other Container Config field, enter the configuration YAML to import environment variables from a ConfigMap. For example, to import all environment variables from a ConfigMap named my-env-vars, use the following YAML:

EnvFrom:
- ConfigMapRef:
    Name: my-env-vars

To import from additional ConfigMaps, duplicate the YAML from lines 2 and 3 in the above example for each config map that you want to import from.

Select individual Environment Variable from a Config Map

Another approach is to select which keys to import from the ConfigMap as environment variables. This method gives you complete control over each environment variable as well as its name, but it requires you to perform more manual configuration.

  1. On the Edit Service: service_name Basic Options page, in the Environment Variables field, enter the configuration for choosing environment variables to import from a ConfigMap. For example, to set a single environment variable (ENV_VAR_ONE) to the value of the MY_ENV_VAR key in the my-env-vars config map, use the following YAML:

- Name: ENV_VAR_ONE
  ValueFrom:
    ConfigMapKeyRef:
      Name: my-env-vars
      Key: MY_ENV_VAR

To add additional environment variables, duplicate the YAML from lines 2 through 5 in the above example for each environment variable that you want to add.

Setting Environment Variables from a Kubernetes Secret

You can import Kubernetes Secrets as Environment Variables.

Create the Kubernetes Secret

  1. In the DuploCloud Portal, navigate to Kubernetes -> Secrets.

  2. Click Add. The Add Kubernetes Secret page opens.

  3. Create a Secret Name, such as my-env-vars.

  4. From the Secret Type list box, select Opaque.

  5. In the Secret Details field, Add Data key/value pairs for each Environment Variable in your ConfigMap, separated by a colon (:). The key is the Environment Variable name, and the value is the Environment Variable's value.

  6. Click Add to create the secret.

Configure Environment Variables

Before you configure Environment Variables, you must create a DuploCloud Service.

Import the entire Secret as Environment Variables

The most straightforward approach is to import the entire Secret as environment variables. Using this approach, your service will recognize each key in the Secret defined as an environment variable.

  1. On the Edit Service: service_name Basic Options page, click Next to navigate to the Advanced Options page.

  2. On the Advanced Options page, in the Other Container Config field, enter the configuration YAML to import environment variables from a Secret. For example, to import all environment variables from a secret named my-env-vars, use the following YAML:

EnvFrom:
- SecretRef:
    Name: my-env-vars

To import from additional secrets, duplicate the YAML from lines 2 and 3 in the above example for each secret that you want to import.

Select individual Environment Variables from a Secret

Another approach is to select which keys to import from the Secret as environment variables. This method gives you complete control over each environment variable as well as its name, but it requires you to perform more manual configuration.

  1. On the Edit Service: service_name Basic Options page, in the Environment Variables field, enter the configuration for choosing specific environment variables to import from a Secret. For example, to set a single environment variable (ENV_VAR_ONE) to the value of the SECRET_ENV_VAR key in the my-env-vars secret, use the following YAML:

- Name: ENV_VAR_ONE
  ValueFrom:
    SecretKeyRef:
      Name: my-env-vars
      Key: SECRET_ENV_VAR

To import from additional secrets, duplicate the YAML from lines 2 and 5 in the above example for each secret that you want to import.

Last updated

Logo

© DuploCloud, Inc. All rights reserved. DuploCloud trademarks used herein are registered trademarks of DuploCloud and affiliates