<p>I am going to utilize the pod IP environment variable in my K8s deployment so that the pod IP should be assigned to a container's argument which is listening on this IP. I tried to fetch pod IP via "status.podIP" and retrieve it in the arg section as follow:</p>

<pre><code>env:
 - name: MY_POD_IP
   valueFrom:
     fieldRef:
       fieldPath: status.podIP
</code></pre>

<p>the container is a proxy application which is listening on the pod IP and its own port number. </p>

<pre><code>- args:
   - --listen=MY_POD_IP:XXXX
</code></pre>

<p>But this setup sometimes returns a binding error as:</p>

<blockquote>
  <p>bind: cannot assign requested address</p>
</blockquote>

<p>and sometimes the server error as:</p>

<blockquote>
  <p>listen tcp: lookup MY_POD_IP: server misbehaving</p>
</blockquote>

<p>If I replace the MY_POD_IP with the actual pod IP, the setup works fine, but since this pod IP is generated dynamically in every deployment, I need to have a general solution to assign this IP to my argument. Any idea or workaround?   </p>

<p>Thank you in advance.</p>

<p>Try this way,</p>

<pre><code>- args:
   - --listen=$(MY_POD_IP):XXXX
</code></pre>

<p>Ref: <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#use-environment-variables-to-define-arguments" rel="nofollow noreferrer">Use environment variables to define arguments</a></p>
