<p>I have a K8s deployment with one pod running among others a container with Envoy sw. I have defined image in such way that if there is an Environment variable EXTRA_OPTS defined it will be appended to the command line to start Envoy.
I want to use that variable to override default configuration as explained in 
<a href="https://www.envoyproxy.io/docs/envoy/latest/operations/cli#cmdoption-config-yaml" rel="nofollow noreferrer">https://www.envoyproxy.io/docs/envoy/latest/operations/cli#cmdoption-config-yaml</a></p>

<p>Environment variable works ok for other command options such as "-l debug" for example. 
Also, I have tested expected final command line and it works.</p>

<p>Dockerfile set Envoy to run in this way:</p>

<pre class="lang-sh prettyprint-override"><code>CMD ["/bin/bash", "-c", "envoy -c envoy.yaml $EXTRA_OPTS"]
</code></pre>

<p>What I want is to set this:</p>

<pre><code>       ...
      - image: envoy-proxy:1.10.0
        imagePullPolicy: IfNotPresent
        name: envoy-proxy
        env:
           - name: EXTRA_OPTS
             value: ' --config-yaml "admin: { address: {  socket_address: { address: 0.0.0.0, port_value: 9902 } } }"'
        ...
</code></pre>

<p>I have succesfully tested running envoy with final command line:</p>

<pre class="lang-sh prettyprint-override"><code>envoy -c /etc/envoy/envoy.yaml --config-yaml "admin: { address: {  socket_address: { address: 0.0.0.0, port_value: 9902 } } }"
</code></pre>

<p>And I have also tested a "simpler" option in EXTRA_OPTS and it works:</p>

<pre><code>       ...
      - image: envoy-proxy:1.10.0
        imagePullPolicy: IfNotPresent
        name: envoy-proxy
        env:
           - name: EXTRA_OPTS
             value: ' -l debug'
        ...
</code></pre>

<p>I would expect Envoy running with this new admin port, instead I'm having param errors:</p>

<pre class="lang-sh prettyprint-override"><code>PARSE ERROR: Argument: {
             Couldn't find match for argument
</code></pre>

<p>It looks like quotes are not being passed to the actual Environment variable into the container... </p>

<p>Any clue??? </p>

<p>Thanks to all</p>

Alicia Factor
<p>You should set <code>["/bin/bash", "-c", "envoy -c envoy.yaml"]</code> as an ENTRYPOINT in you dockerfile or use <code>command</code> in kubernetes and then use <code>args</code> to add additional arguments.  </p>

<p>You can find more information in <a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#entrypoint" rel="nofollow noreferrer">docker documentation</a></p>

<p>Let me explain by example:</p>

<p><code>$ docker build -t fl3sh/test:bash .</code></p>

<pre><code>$ cat Dockerfile
FROM ubuntu
RUN echo '#!/bin/bash' &gt; args.sh &amp;&amp; \
    echo 'echo "$@"' &gt;&gt; args.sh &amp;&amp; \
    chmod -x args.sh
CMD ["args","from","docker","cmd"]
ENTRYPOINT ["/bin/bash", "args.sh", "$ENV_ARG"]
</code></pre>

<pre><code>cat args.yaml

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: args
  name: args
spec:
  containers:
  - args:
    - args
    - from
    - k8s
    image: fl3sh/test:bash
    name: args
    imagePullPolicy: Always
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}

Output:
pod/args $ENV_ARG args from k8s
</code></pre>

<pre><code>cat command-args.yaml

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: command-args
  name: command-args
spec:
  containers:
  - command:
    - /bin/bash
    - -c
    args:
    - 'echo args'
    image: fl3sh/test:bash
    imagePullPolicy: Always
    name: args
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}

Output:
pod/command-args args
</code></pre>

<pre><code>cat command-env-args.yaml

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: command-env-args
  name: command-env-args
spec:
  containers:
  - env:
    - name: ENV_ARG
      value: "arg from env"
    command:
    - /bin/bash
    - -c
    - exec echo "$ENV_ARG"
    image: fl3sh/test:bash
    imagePullPolicy: Always
    name: args
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}

Output:
pod/command-env-args arg from env
</code></pre>

<pre><code>cat command-no-args.yaml

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: command-no-args
  name: command-no-args
spec:
  containers:
  - command:
    - /bin/bash
    - -c
    - 'echo "no args";echo "$@"'
    image: fl3sh/test:bash
    name: args
    imagePullPolicy: Always
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}

Output:
pod/command-no-args no args

#notice ^ empty line above  
</code></pre>

<pre><code>cat no-args.yaml

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: no-args
  name: no-args
spec:
  containers:
  - image: fl3sh/test:bash
    name: no-args
    imagePullPolicy: Always
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}

Output:
pod/no-args $ENV_ARG args from docker cmd
</code></pre>

<p>If you need to recreate my example you can use this loop to get this output like above:</p>

<pre><code>for p in `kubectl get po -oname`; do echo cat ${p#*/}.yaml; echo ""; \
cat ${p#*/}.yaml; echo -e "\nOutput:"; printf "$p "; \
kubectl logs $p;echo "";done
</code></pre>

<p>Conclusion if you need to pass env as arguments use:</p>

<pre><code>    command:
    - /bin/bash
    - -c
    - exec echo "$ENV_ARG"
</code></pre>

<p>I hope now it is clear.</p>
