Kubernetes - set env var using the value of one of the auto generated service env vars

8/15/2018

Kubernetes automatically generates several environment variables for you, like SERVICE1_SERVICE_HOST and SERVICE1_SERVICE_PORT. I would like to use the value of these variables to set my own variables in the deployment.yml, like below:

env:
- name: MY_NEW_VAR
  value: ${SERVICE1_SERVICE_HOST}

For some reason Kubernetes isn't able to resolve this. When I go inside the container it turns out it has been assigned as a literal string, giving me MY_NEW_VAR = ${SERVICE1_SERVICE_HOST}.

Is there a way to assign the value of ${SERVICE1_SERVICE_HOST} instead?

-- DraegerMTN
kubectl
kubernetes

1 Answer

8/16/2018

The syntax is $(SERVICE1_SERVICE_HOST), as one can see in the fine manual

-- mdaniel
Source: StackOverflow