<p>I am using Kubernetes Engine on the Google Cloud Platform. I have a pod running a process in a Docker scratch container. I also have a load balancer service that gives me access to the pod from the outside world.</p>

<p>The process running in the pod needs to know what its external IP address is. How can I get this?</p>

<p>Prior to using Kubernetes Engine I was using Compute Engine and could find the external IP address by the following:</p>

<pre><code>curl -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip
</code></pre>

<p>Are there any internal tools I can use that would be available to my process? Or would I need the process to call an external site that can mirror back the IP address?</p>

<p>Every Pod (unless configured not to do so) has valid kubernetes credentials in <code>/var/run/secrets/kubernetes.io/serviceaccount/token</code> <a href="https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/#accessing-the-api-from-a-pod" rel="nofollow noreferrer">as described here</a> so the answer is to use the kubernetes API to ask the <code>Service</code> in front of the Pod(s) for its <code>status:loadBalancer:ingress:ip:</code> <a href="https://v1-8.docs.kubernetes.io/docs/api-reference/v1.8/#loadbalanceringress-v1-core" rel="nofollow noreferrer">as described here</a> which I have every reason to believe GKE will keep up-to-date with any changes to the load balancer. The kubernetes API is always(?) located at <code>https://kubernetes</code> (that's normally enough, or <code>https://kubernetes.default.svc.cluster.local</code> is its full name), so there should be very little configuration the Pod would need in order to carry out the lookup.</p>
<p>The asterisk to that response is that one must provide the name of the Service to the Pod(s) of the Service sitting in front of it, because (for the most part) there is no way for the Pod to know how many Services point to it.</p>
