<p>I am hosting my application on GKE. The kubectl version installed in the server is <code>v1.10.11-gke.1</code> and nginx-ingress is <code>nginx-ingress-0.28.2</code></p>

<p>I would like to see the client IP address in my logs. For now, I can only see the pod IP address for example:</p>

<p><code>2019-02-14 15:17:21.000 EAT
10.60.1.1 - [10.60.1.1] - - [14/Feb/2019:12:17:21 +0000] "GET /user HTTP/2.0" 404 9 "-" "Mozilla/5.0 (Macintosh;</code></p>

<p>My service has tls managed by letsencrypt. How can I get the client IP address on the logs? </p>

<p><a href="https://i.stack.imgur.com/05Ky1.png" rel="nofollow noreferrer">screenshot of log files</a></p>

Samuel Magondu
<p>I reproduced the behavior you observed in a test. In my own container logs, on a job running with an nginx-ingress controller, we can only see the internal IP address assuming that nginx-ingress-controller service YAML file is set to:</p>

<pre><code>externalTrafficPolicy: Cluster
</code></pre>

<p>Setting traffic to 'Cluster” means that all the nodes can receive the requests. 'Cluster obscures the client source IP', the requests also could be <a href="https://kubernetes.io/docs/tutorials/services/source-ip/#source-ip-for-services-with-type-clusterip" rel="nofollow noreferrer">SNAT'd</a> to a node that has the running pod.</p>

<p>However, If you change:</p>

<pre><code>externalTrafficPolicy: Local
</code></pre>

<p>The client source IP are exposed. “Local” preserves the client source IP but may cause imbalanced traffic spreading.This due to the fact that only the Nodes that are running the pods will be considered healthy by the network load balancer. The requests will be sent only to healthy nodes.</p>

<p>Some background explanation on how to <a href="https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#preserving-the-client-source-ip" rel="nofollow noreferrer">preserve source IP</a> in your containers and some further reading on the hops for source IP for services with <a href="https://kubernetes.io/docs/tutorials/services/source-ip/#source-ip-for-services-with-type-nodeport" rel="nofollow noreferrer">Type=Nodeport</a> can be useful to understand what is happening. </p>
