Preserve original requester IPa address

5/7/2020

How can I preserve origin client IP when using ingress-controller on Kubernetes?

I didn't see any solution in the documentation.

This link is broken: http://ingress.kubernetes.io/preserve-host

-- 0x77dev
kubernetes
kubernetes-ingress
nginx-ingress

1 Answer

5/7/2020

From the doc

By default NGINX uses the content of the header X-Forwarded-For as the source of truth to get information about the client IP address. This works without issues in L7 if we configure the setting proxy-real-ip-cidr with the correct information of the IP/network address of trusted external load balancer.

If the ingress controller is running in AWS we need to use the VPC IPv4 CIDR.

Another option is to enable proxy protocol using use-proxy-protocol: "true".

In this mode NGINX does not use the content of the header to get the source IP address of the connection.

If you are using a L4 proxy to forward the traffic to the NGINX pods and terminate HTTP/HTTPS there, you will lose the remote endpoint's IP address. To prevent this you could use the Proxy Protocol for forwarding traffic, this will send the connection details before forwarding the actual TCP connection itself.

Amongst others ELBs in AWS and HAProxy support Proxy Protocol.

-- Arghya Sadhu
Source: StackOverflow