<p>I have a case where i'd like to set the IP address of the pod as part of the container environment variables as well as the port (which can be hardcoded to default8080 for example) </p>

<p>something like below but I need to append the port as part of that too. so that APPLICATION_SERVER would result as <strong>111.<em></strong>.<strong></em>.000:8080</strong> something like this i guess.</p>

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

tosi
<p>That information is available in the <a href="https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/#the-downward-api" rel="nofollow noreferrer">Downward API</a> </p>

<p>The Values you are looking are available as env vars from the Downward API</p>

<ul>
<li>status.podIP - the pod’s IP address </li>
<li>spec.serviceAccountName - the
pod’s service account name </li>
<li>spec.nodeName - the node’s name</li>
<li>status.hostIP - the node’s IP</li>
</ul>

<h1>Podspec</h1>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: dapi-envars
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ "sh", "-c"]
      args:
      - while true; do
          echo -en '\n';
          echo "Application Server $(APPLICATION_SERVER)";
          sleep 10;
        done;
      env:
        - name: MY_POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: APPLICATION_SERVER
          value: "$(MY_POD_IP):8080"
</code></pre>

<p>Output</p>

<pre><code>kubectl logs dapi-envars

Application Server 10.244.0.7:8080

Application Server 10.244.0.7:8080

Application Server 10.244.0.7:8080

Application Server 10.244.0.7:8080

Application Server 10.244.0.7:8080
</code></pre>

<p><a href="https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/</a></p>
