<p>Regarding my Kubernetes setup, I am using the Nginx Ingress controller. To handle incoming requests, I utilize a Cloudflare worker to interact with my Kubernetes cluster. The worker sends a request with the following header:</p>
<p>X-Forwarded-For: xxx.xxx.xxx.xxx, xxx2.xxx2.xxx2.xxx2</p>
<p>In this header:</p>
<p>xxx.xxx.xxx.xxx represents the real IP address.
xxx2.xxx2.xxx2.xxx2 represents the Cloudflare worker IP address.</p>
<p>However, upon inspecting the pods inside the Kubernetes cluster (tcpdump), I notice that the headers received are as follows:</p>
<p>X-Real-IP: xxx2.xxx2.xxx2.xxx2
X-Forwarded-For: xxx2.xxx2.xxx2.xxx2
X-Original-Forwarded-For: xxx.xxx.xxx.xxx,xxx2.xxx2.xxx2.xxx2</p>
<p>I want to ensure that the actual client IP address (xxx.xxx.xxx.xxx) is available inside the pods by the X-Forwarded-For header. How can I achieve this?</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: demo-ingress2
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.org/client-max-body-size: &quot;100m&quot;
    nginx.org/proxy-connect-timeout: 300s
    nginx.org/proxy-read-timeout: 300s
    nginx.org/proxy-send-timeout: 300s
    nginx.ingress.kubernetes.io/proxy-connect-timeout: &quot;300&quot;
    nginx.ingress.kubernetes.io/proxy-read-timeout: &quot;300&quot;
    nginx.ingress.kubernetes.io/proxy-send-timeout: &quot;300&quot;
spec:
  rules:


    - host: test.com
      http:
        paths:
          - pathType: Prefix
            path: /
            backend:
              service:
                name: myservice
                port:
                  number: xxxx


---
apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
  name: nginx-configuration
  namespace: default
data:
    use-forwarded-headers: &quot;true&quot;
    compute-full-forwarded-for: &quot;true&quot;
    use-proxy-protocol: &quot;true&quot;
</code></pre>

thibd
<p>Found the answer:</p>
<p>You need to override nginx conf file <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/custom-template/" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/custom-template/</a></p>
<p>Or have a config map like:</p>
<pre><code>apiVersion: v1
data:
  allow-snippet-annotations: &quot;true&quot;
  enable-real-ip: &quot;true&quot;
  compute-full-forwarded-for: &quot;true&quot;
  use-forwarded-headers: &quot;true&quot;
kind: ConfigMap
metadata:
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.7.1
  name: ingress-nginx-controller
  namespace: ingress-nginx
</code></pre>
