Setting Environment Variables (EVs) from a ConfigMap or Secret
Set EVs from the Kubernetes ConfigMap
Last updated
Set EVs from the Kubernetes ConfigMap
Last updated
© DuploCloud, Inc. All rights reserved. DuploCloud trademarks used herein are registered trademarks of DuploCloud and affiliates
In Kubernetes, you populate environment variables from application configurations or secrets.
In the DuploCloud Portal, navigate to Kubernetes -> Config Maps.
Click Add. The Add Config Map pane displays.
Name the ConfigMap you want to create, such as my-config-map
.
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.
Click Create.
In the DuploCloud Portal, navigate to Kubernetes -> Services.
Select the Service you want to modify from the Name column.
Click the Actions menu and select Edit.
You can import the entire ConfigMap as environment variables or choose specific keys to import 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.
On the Edit Service: service_name Basic Options page, click Next to navigate to the Advanced Options page.
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:
To import from additional ConfigMaps, duplicate the YAML from lines 2 and 3 in the above example for each ConfigMap you want to import from.
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 and its name, but it requires more manual configuration.
On the Edit Service: service_name Basic Options page, in the Environment Variables field, enter the configuration for 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:
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.
You can import Kubernetes Secrets as Environment Variables.
In the DuploCloud Portal, navigate to Kubernetes -> Secrets.
Click Add. The Add Kubernetes Secret page opens.
Create a Secret Name, such as my-env-vars
.
From the Secret Type list box, select Opaque.
In the Secret Details field, add key/value pairs for each EV in your ConfigMap, separated by a colon (:
). The key is the EV name, and the value is the EV value.
Click Add to create the secret.
Before you configure environment variables, you must create a DuploCloud Service.
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 EV.
On the Edit Service: service_name Basic Options page, click Next to navigate to the Advanced Options page.
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:
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.
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 and its name, but it requires more manual configuration.
On the Edit Service: service_name Basic Options page, in the Environment Variables field, enter the configuration for 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:
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.