<p>I want to pass some values from Kubernetes yaml file to the containers. These values will be read in my Java app using <code>System.getenv("x_slave_host")</code>.
I have this dockerfile: </p>

<pre><code>FROM jetty:9.4
...
ARG slave_host
ENV x_slave_host $slave_host
...
$JETTY_HOME/start.jar -Djetty.port=9090
</code></pre>

<p>The kubernetes yaml file contains this part where I added <code>env</code> section:</p>

<pre><code>apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: master
spec:
  template:
    metadata:
      labels:
        app: master
    spec:
      volumes:
      - name: shared-data
        emptyDir: {}
      containers:
      - name: master
        image: xregistry.azurecr.io/Y:latest
        ports:
        - containerPort: 9090
        volumeMounts:
        - name: shared-data
          mountPath: ~/.X/experiment
      - env:
        - name: slave_host
          value: slavevalue
      - name: jupyter
        image: xregistry.azurecr.io/X:latest
        ports:
        - containerPort: 8000
        - containerPort: 8888
        volumeMounts:
        - name: shared-data
          mountPath: /var/folder/experiment
      imagePullSecrets:
      - name: acr-auth
</code></pre>

<p>Locally when I did the same thing using docker compose, it worked using args. This is a snippet:</p>

<pre><code>  master:
    image: master
    build:
      context: ./master
      args:
        - slave_host=slavevalue
    ports:
      - "9090:9090"
</code></pre>

<p>So now I am trying to do the same thing but in Kubernetes. However, I am getting the following error (deploying it on Azure):</p>

<pre><code>    error: error validating "D:\\a\\r1\\a\\_X\\deployment\\kub-deploy.yaml": error validating data: field spec.template.spec.containers[1].name for v1.Container is required; if you choose to ignore these errors, turn validation off with --validate=false
</code></pre>

<p>In other words, how to rewrite my docker compose file to kubernetes and passing this argument.</p>

<p>Thanks!</p>

<p>env section should be added under containers, like this:</p>

<pre><code>  containers:
  - name: master
    env:
    - name: slave_host
      value: slavevalue
</code></pre>
