# Use Environment Variables to Customize Microservices

This tutorial describes how to use environment variables to customize the behavior of microservices. Using environment variables as a configuration mechanism allows the same Linux image to run in development and production environments. This is especially useful when managing sensitive information via Kubernetes Secrets.

The entando.json file makes environment variables available to a microservice in a docker-based bundle. There are two options:

  1. Inject the variables using a key-value pair
  2. Inject a reference to an existing Kubernetes Secret

This tutorial will demonstrate both of these options. The microservice will receive one environment value directly as plain text in the pod YAML and the other indirectly through a referenced Secret.

# Prerequisites

# Add Environment Variables to the Microservice

  1. To determine YOUR-BUNDLE-ID, run the following command. Supply the full bundle URL, remembering to update the placeholders with your Docker organization and your bundle name.
ent ecr get-bundle-id docker://registry.hub.docker.com/YOUR-ORG/YOUR-BUNDLE
  1. Create a Secret named YOUR-BUNDLE-ID-my-secret with key-value pair mySecretKey=mySecretValue. Replace YOUR-BUNDLE-ID with the output of the previous step.
ent kubectl create secret generic YOUR-BUNDLE-ID-my-secret --from-literal=mySecretKey=mySecretValue -n entando
  1. Insert the following env section into the microservice in entando.json, remembering to replace YOUR-BUNDLE-ID. By convention, environment variables are all caps and K8s resource names are hyphenated.
"env": [
  { "name": "SIMPLE_VAR",
    "value": "mySimpleValue" 
  { "name": "SECRET_VAR",
    "secretKeyRef": {
        "name": "YOUR-BUNDLE-ID-my-secret", 
        "key": "mySecretKey"
  1. Build and deploy the updated bundle

# Verify the Environment Variables

  1. When the installation is complete, shell into the pod created by the plugin, where YOUR-PLUGIN-POD-NAME begins with the prefix pn- followed by YOUR-BUNDLE-ID:
ent kubectl exec -it YOUR-PLUGIN-POD-NAME -- /bin/bash
  1. Confirm the environment variables are present:

Expected output:

SIMPLE_VAR=mySimpleValue, SECRET_VAR=mySecretValue


You have learned how to use environment variables with microsevices on the Entando Platform!