<p>I have a nodejs app which has refers to the IP Address of the kubernetes service/load balancer public IP. Is there a way to get it from the process/env variables in runtime?</p>

<p>e..g <code>process.env.ENV_VARIABLE</code> and what is the env variable name</p>

<p>Thanks</p>

<p>It's <strong>not available</strong> as an environment variable. Also keep in mind that a pod can receive traffic from multiple load balancers and also the external IP could change after the Pod started, leaving a stale value; so an IP in an environment variable might not be an adequate solution.</p>

<p>If you are using an <strong>Ingress</strong> object you can determine it's external IP by querying the Kubernetes apiserver (try <code>kubectl get myingress -o yaml</code>, see the <code>status:</code> part).</p>

<p>For a particular incoming <strong>http request</strong> check the <code>X-Forwarded-For:</code> header for the load balancer's IP.</p>

<p>Since the question is tagged <a href="https://stackoverflow.com/questions/tagged/google-container-engine">google-container-engine</a>, you can also use <strong>gcloud</strong> to get that IP (perhaps from an <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">initContainer</a> or at startup):</p>

<ul>
<li>If you are using Ingress: <code>gcloud compute forwarding-rules describe k8s-fw-YOURNAMESPACE-YOURINGRESSNAME--YOURHASHVALUE --global --format='value(IPAddress)'</code></li>
<li>If you have a static IP reserved: <code>gcloud compute addresses describe my-static-ip-name --global --format='value(address)'</code></li>
</ul>
