<p>I'm running a gunicorn+flask service in a docker container with Google Container Engine. I set up the cluster following the tutorial at <a href="http://kubernetes.io/docs/hellonode/" rel="nofollow">http://kubernetes.io/docs/hellonode/</a></p>

<p>The <code>REMOTE_ADDR</code> environmental variable always contains an internal address in the Kubernetes cluster. What I was looking for is <code>HTTP_X_FORWARDED_FOR</code> but it's missing from the request headers. Is it possible to configure the service to retain the external client ip in the requests?  </p>

<p>If anyone gets stuck on this there is a better approach.
You can use the following annotations depending on your kubernetes version:</p>

<pre><code>service.spec.externalTrafficPolicy: Local 
</code></pre>

<p>on 1.7</p>

<p>or </p>

<pre><code>service.beta.kubernetes.io/external-traffic: OnlyLocal
</code></pre>

<p>on 1.5-1.6</p>

<p>before this is not supported</p>

<p>source: <a href="https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/" rel="noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/</a></p>

<p>note that there are caveats:
<a href="https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#caveats-and-limitations-when-preserving-source-ips" rel="noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#caveats-and-limitations-when-preserving-source-ips</a></p>
