<h3>Setup</h3>
<p>I'm playing around with K8s and I set up a small, single-node, bare metal cluster. For this cluster I pulled the NGINX Ingress Controller config <a href="https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.0/deploy/static/provider/cloud/deploy.yaml" rel="nofollow noreferrer">from here</a>, which is coming from the <a href="https://kubernetes.github.io/ingress-nginx/deploy/" rel="nofollow noreferrer">official getting started guide</a>.</p>
<h3>Progress</h3>
<p>Ok, so pulling this set up a bunch of things, including a LoadBalancer in front. I like that.</p>
<p>For my app <em>(single pod, returns the caller IP)</em> I created a bunch of things to play around with. I now have SSL enabled and another ingress controller, which I pointed to my app's service, which then points to the deployed pod. This all works perfectly, I can browse the page with https. See:</p>
<p><a href="https://i.stack.imgur.com/ufKt8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ufKt8.png" alt="Cluster setup" /></a></p>
<h2>BUT...</h2>
<p>My app is not getting <strong>the original IP from the client</strong>. All client requests end up as coming from 10.42.0.99... here's the controller config from <code>describe</code>:</p>
<p><a href="https://i.stack.imgur.com/dsDvz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dsDvz.png" alt="Ingress Controller config" /></a></p>
<h3>Debugging</h3>
<p>I tried like <a href="https://www.google.com/search?q=nginx-ingress+load+balancer+get+real+IP" rel="nofollow noreferrer">50 solutions</a> that were proposed online, none of them worked (ConfigMaps, annotations, proxy mode, etc). And I debugged in-depth, there's no <code>X-Forwarder-For</code> or any similar header in the request that reaches the pod. Previously I tested the same app on apache directly, and also in a docker setup, it works without any issues.</p>
<p>It's also worth mentioning that I looked into the ingress controller's pod and I already saw the same internal IP in there. I don't know how to debug the controller's pod further.</p>
<p>Happy to share more information and config if it helps.</p>
<h3>UPDATE 2021-12-15</h3>
<p>I think I know what the issue is... I didn't mention how I installed the cluster, assuming it's irrelevant. Now I think it's the most important thing 😬</p>
<p>I set it up <a href="https://rancher.com/docs/k3s/latest/en/networking/#how-the-service-lb-works" rel="nofollow noreferrer">using K3S</a>, which has <a href="https://github.com/k3s-io/klipper-lb" rel="nofollow noreferrer">its own LoadBalancer</a>. And through debugging, I see now that all of my requests in NGINX have the IP of the load balancer's pod...</p>
<p>I still don't know how to make this Klipper LB give the source IP address though.</p>
<h3>UPDATE 2021-12-17</h3>
<p>Opened <a href="https://github.com/k3s-io/klipper-lb/issues/31" rel="nofollow noreferrer">an issue</a> with the Klipper LB.</p>

<p>Make sure your Nginx ingress configmap have enabled user IP <code>real-ip-header: proxy_protocol</code> try updating this line into configmap.</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app.kubernetes.io/component: controller
  name: ingress-nginx-controller
  namespace: ingress-nginx
data:
  compute-full-forwarded-for: &quot;true&quot;
  use-forwarded-headers: &quot;false&quot;
  real-ip-header: proxy_protocol
</code></pre>
<p>still if that not work you can just inject this config as annotation your ingress configuration and test once.</p>
<pre><code>nginx.ingress.kubernetes.io/configuration-snippet: |
      more_set_headers &quot;X-Forwarded-For $http_x_forwarded_for&quot;;
</code></pre>
