Can we use env variable as a value for a ENV variable in container of openshift deployment?

1.2k Views Asked by At

I have to login to Openshift with api and I am mentioning apikey in the deployment.yaml file like below:

    apiVersion: extensions/v1beta1
kind: Deployment
metadata:
 name: abc
spec:
 replicas: 1
 template:
   metadata:
     labels:
       app: abc
       version: v1
   spec:
     containers:
      - name: chaos
        image: abcusr/abc:v1
        imagePullPolicy: Always
        env:
         - name: HOST
           value: $host
         - name: NAMESPACE
           value: $namespace
         - name: APIKEY
           value: $apikey

These 3 env variables are set in travis as a env variables. But when I run the build my deployment was not successful. It was giving error:

 error: --server and passing the server URL as an argument are mutually exclusive

But when I hard code all these values it works.

1

There are 1 best solutions below

2
Oligzeev On

The env variables ($host etc) aren't previously defined because value in env variable is described as:

Variable references $(VAR_NAME) are expanded using the previous defined environment variables in the container and any service environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not. Defaults to "".

However, it's a better approach to use a template with the deployment (and all other objects for you application) and all such variables as template's parameters. So you can set that parameters in process-template phase.