Working with Environment Variables

Learn how to work with Environment Variables for Containers in Humanitec.

What are Environment Variables?

Environment Variables are key-value pairs that are provided by the environment that a process runs in. They are a very common and practical way of configuring containers. Environment Variables can be easily changed and do not require updates to the file systems as with Configuration Files.

On deployment, Humanitec collects Environment Variables defined for containers in a Workload into either a ConfigMap or Secret Kubernetes object. They are then made available to containers running in a pod.

Using Placeholders

Sometimes the value of some configuration will change depending on the Environment that a workload is deployed into. For example, you may want your workload to connect to a different database in a development than in a production environment. To allow for this, Humanitec provides placeholders that can be inserted into the variable values.

Placeholders are of the form ${...} where the content is a placeholder path. Any number of placeholders can be included in the value of a variable. For example:

Hello ${values.PLACEHOLDER_EXAMPLE}!

Will resolve the shared value PLACEHOLDER_EXAMPLE at deployment time and insert the value into the string above.

Find out more about placeholder you can use:

Secrets

Sometimes the value of an environment variable contains a sensitive value that should not be visible to other developers. An example of this would be database credentials. Secrets should be stored as shared Values and Secrets and then referenced in an Environment Variable using a placeholder. If the content of a placeholder is a secret, Humanitec will automatically convert the entire value into a secret.

Add an Environment Variable

Environment Variables are added as "Variables" to Containers inside a Workload.

UI
CLI
API
UI
  1. Enter the Workload Details screen for the Workload you want to work on.

  2. Ensure you are in Draft mode. If you are not, you can select it from the Deployment drop-down.

  3. Choose the container in the workload you want to update.

  4. Enter the name of the Environment Variable you want to make available to the Container. The name must only consist of alphanumeric characters, -, _ or ..

  5. Enter the value for the Environment Variable including any Placeholders you require. Typing Enter will save the value and provide a new row to enter further variables.

Steps for adding Environment Variables to a Container in a Workload.

Typing Enter or Tab moves you to the next field You can enter multi-line values by using Shift + Enter to add new lines. Copy and pasting multi-line values also works.

CLI

Our CLI is currently in closed beta. Please contact us if you want to learn more.

API

Adding Environment Variables involves adding a property to the variables section of the container object in the spec section of a module in a Deployment Set. See Deployment Deltas in the API Documentation for more details of how this can be done.

Updating or Deleting an Environment Variable

Environment Variables are added as "Variables" to Containers inside a Workload.

UI
CLI
API
UI
  1. Enter the Workload Details screen for the Workload you want to work on.

  2. Ensure you are in Draft mode. If you are not, you can select it from the Deployment drop-down.

  3. Choose the container in the workload you want to update.

  4. Click on the Key field to change the name. The name must only consist of alphanumeric characters, -, _ or ..

  5. Click on the Value field to update the value. Typing Enter will save the value and provide a new row to enter further variables.

  6. Click the ⓧ button to delete the Environment Variable.

Steps to Update or Delete an Environment Variable for a Container in a Workload.
CLI

Our CLI is currently in closed beta. Please contact us if you want to learn more.

API

Updating or deleting Environment Variables involves updating the variables section of the container object in the spec section of a module in a Deployment Set. See Deployment Deltas in the API Documentation for more details of how this can be done.