0

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.

Mansi
  • 111
  • 1
  • 10
  • You're saying the `value` are valid environment variables on the machine where your yaml is defined? You'll likely need to process the yaml locally first to have those variables replaced. Something like `envsubst` should work https://stackoverflow.com/a/11050943 – Will Gordon Feb 17 '20 at 13:44

1 Answers1

0

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.

Oligzeev
  • 511
  • 3
  • 7
  • I did this way export apikey=XXXXXXXXXXXXXXXXX and in deployment.yaml file did `env: - name: HOST value: XXXXXXXXXX - name: NAMESPACE value: XXXXXX - name: APIKEY value: "${apikey}"` – Mansi Feb 18 '20 at 05:01
  • I created secret and applied it and used in deployment like this `name: APIKEY valueFrom: secretKeyRef: name: ocapikey key: APIKEY` this worked for me – Mansi Feb 21 '20 at 13:42