<p>I have a container with the following spec:</p>

<pre><code>containers:
      - name: test-container
        image: REDACTED
        env:
        - name: DISPLAY
          value: ":10.0"   &lt;---------------------
        - name: NODE_ENV
          value: "production"
        - name: ENDPOINT
          value: REDACTED
        ports:
        - containerPort: 8080
        volumeMounts:
        - name: x11
          mountPath: /tmp/.X11-unix
      volumes:
      - name: x11
        hostPath:
          path: /tmp/.X11-unix
</code></pre>

<p>sidenote: What this is doing is it's allowing me to render components on the host node, but perform the computation inside my container.</p>

<p>Right now I have DISPLAY hardcoded to ":10.0", but I want to do something like:</p>

<pre><code>env:
        - name: DISPLAY
          value: ":$HOST_DISPLAY"
</code></pre>

<p>Which will mount the host node's DISPLAY variable (rather than hardcoding and guessing what it will be), so that if a node has ":0" or any other variable set it will forward/inject it into the container dynamically.</p>

<p>Any way to accomplish this? If it helps I can use an ansible operator</p>

<p>Edit to further explain:</p>

<p>Imagine a pod that was a simple http server that when you hit it with a browser, showed you the operating system of the node it is being run on. Lets say the node had an environment variable called OPERATING_SYSTEM. Node A has OPERATING_SYSTEM=Windows  Node B has OPERATING_SYSTEM=Linux. How could I configure this pod to display the node's operating system. <em>NOT THE CONTAINER OPERATING SYSTEM</em></p>

<p>Another example:</p>

<p>Imagine a pod that was a simple http server that when you hit it with a browser, it gave you back the ID of the node that it is running on. Lets say Node 1 has an environment variable called NODE_ID=123 and Node 2 has an environment variable called NODE_ID=456. When any pod gets scheduled on one of these two arbitrary nodes, it can access these NODE environment variables to correctly display which node it's running on</p>

<p>I almost want to do this, except with node.fields: <a href="https://v1-15.docs.kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/" rel="nofollow noreferrer">https://v1-15.docs.kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/</a></p>

user2896438
<p>There are few ways to pass environment variables.</p>

<ol>
<li>Define env variables in container, for example like in <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/#define-an-environment-variable-for-a-container" rel="nofollow noreferrer">this doc</a>.</li>
<li>Define in Pod/Deployment config like <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/#using-environment-variables-inside-of-your-config" rel="nofollow noreferrer">here</a>.</li>
<li>From Secrets from <a href="https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets-as-environment-variables" rel="nofollow noreferrer">this example</a>.</li>
</ol>

<p>To pass new environment variables to container you need to use <code>ConfigMap</code> or <code>Secret</code>.</p>

<p>Unfortunately, that what you want to achieve is impossible to obtain in pure Kubernetes due to <code>Kubernetes concepts</code>. As per <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/" rel="nofollow noreferrer">doc</a>:</p>

<blockquote>
  <p>A Pod encapsulates an application’s container (or, in some cases,
  multiple containers), storage resources, a unique network IP, and
  options that govern how the container(s) should run. A Pod represents
  a unit of deployment: a single instance of an application in
  Kubernetes, which might consist of either a single container or a
  small number of containers that are tightly coupled and that share
  resources.</p>
</blockquote>

<p>If you will <code>kubectl describe &lt;pod-name&gt;</code> you will have only name of host, because that's all what Kubernetes needs. Kubernetes make sure to run whole deployment application, no mather on what node (unitl you specify <code>nodeSelector</code>). It's how Kubernetes was designed. For detailed information you should reat <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod/" rel="nofollow noreferrer">this docs</a>.</p>

<p>You can add some <code>tags</code> with <code>ansible</code>, <code>python</code>, etc to question. Maybe if you would use some scripts/libraries it could be done, but you will not achieve this using <code>pure Kubernetes</code>.</p>
