Getting the real client ip on NodeJs behind a NodeBalancer
Hi all!
I have a Kubernetes cluster and my Linodes are running NodeJs. On my Linode I need to get the IP of the client that requested the application. These x-forwarded-for, x-real-ip, remote-address headers do not work, I even tried with upper and lower case. They always return the IP of the NodeBalancer.
These tutorials are what I found about this topic, but nothing works with NodeJs.
https://www.linode.com/community/questions/23073/get-the-client-ip-behind-a-loadbalancer
https://www.linode.com/community/questions/17963/how-do-i-see-the-real-ip-address-of-a-connection-through-a-nodebalancer
https://www.linode.com/docs/products/networking/nodebalancers/guides/client-ip/
Would be great if someone already faced this challenge and could provide a proper solution. Thanks in advance :)
1 Reply
According to the Kubernetes Documentation you should be able to preserve the client's IP by setting the load balancer service's externalTrafficPolicy to local. This should allow you to view the IP address of the client connecting to your node.js application.
This answer from this question on Stack Exchange has a bit more information related to the issue.