<p>I am using a Nginx Ingress Controller in a Kubernetes Cluster. I've got an application within the cluster, which was available over the internet. Now I'm using the Ingress Controller to access the application, with the intent of showing some custom errors.</p>
<p>If i access the application (which is not written by myself, therefore I can't change things there), it receives the IP address of the <code>nginx-ingress-controller-pod</code>. The logs of the <code>nginx-ingress-controller-pod</code> indicate that the remote address is a different one.</p>
<p>I've already tried things like <code>use-proxy-protocol</code>, then I would be able to use <code>$remote_addr</code> and get the right IP. But as I mentioned I am not able to change my application, so I have to &quot;trick&quot; the ingress controller to use the <code>$remote_addr</code> as his own.
How can i configure the ingress, so the application will get the request from the remote IP and not from the <code>nginx-ingress-controller-pod</code> IP? Is there a way to do this?</p>
<p>Edit: I'm using a bare metal kubernetes installation with kubernetes v1.19.2 and the nginx chart <code>ingress-nginx-3.29.0</code>.</p>

black_hawk
<p><strong>It could not achievable by using layer 7 ingress controller.</strong></p>
<p>If Ingress preserves the source IP then response will got directly from the app pod to the client, so the client will get a response from a IP:port different from what he connected to. Or even worse - client's NAT drops the response completely because it doesn't match the existing connections.</p>
<p>You can take a look at this <a href="https://stackoverflow.com/questions/63836681/preserve-source-ip-on-kubernetes-bare-metal-with-ingress-nginx-iptables-and-met">similar question</a> on stackoverflow with accepted answer:</p>
<blockquote>
<p>As ingress is above-layer-4 proxy. There is no way you can preserve SRC IP in layer 3 IP protocol. The best is and I think Nginx Ingress already been set by default that they put the &quot;X-Forwarded-For&quot; header in any HTTP forward.
Your app supposes to log the X-Forwarded-For header</p>
</blockquote>
<p>You can try to workaround by following <a href="https://docs.ovh.com/gb/en/kubernetes/getting-source-ip-behind-loadbalancer/" rel="nofollow noreferrer">this article</a>. It could help you to preserve your IP.</p>
<p>I also recommend this <a href="https://blog.envoyproxy.io/introduction-to-modern-network-load-balancing-and-proxying-a57f6ff80236" rel="nofollow noreferrer">very good article</a> about load balancing and proxying. You will also learn a bit about load balancing on L7:</p>
<blockquote>
<p>L7 load balancing and the OSI model
As I said above in the section on L4 load balancing, using the OSI model for describing load balancing features is problematic. The reason is that L7, at least as described by the OSI model, itself encompasses multiple discrete layers of load balancing abstraction. e.g., for HTTP traffic consider the following sublayers:</p>
<ul>
<li>Optional Transport Layer Security (TLS). Note that networking people argue about which OSI layer TLS falls into. For the sake of this discussion we will consider TLS L7.</li>
<li>Physical HTTP protocol (HTTP/1 or HTTP/2).</li>
<li>Logical HTTP protocol (headers, body data, and trailers).</li>
<li>Messaging protocol (gRPC, REST, etc.).</li>
</ul>
</blockquote>
