I have my website hosted on Kubernetes Cluster with a LoadBalancer and everything works as it should. I stumbled upon some documentation in how to get the visitor/client IP
Long story short: setup proxy protocol in the loadbalancer and set externalTrafficPolicy: "Local" Most of the people seem satisfied with that approach. Though, since I am completely new to Kubernetes…
How do you actually access that IP? Is it in a log file? Because when I run kubectl logs my-app -c my-container --since=1h the output is always empty, even if I am interacting with the page. But most importantly, even if it is in a log file, how can I pass it to my NodeJS application?
I also followed this guide https://www.digitalocean.com/community/tutorial_series/from-containers-to-kubernetes-with-node-js but there is no mention in how you can access/forward the IP to the node front-end.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi @mazzespazze
I understand that you want to preserver client IP address. Proxy protocol enables is the fact that it will preserve the X-Forwarded-For HTTP header which will container the original client IP to achieve this you need to follow below :
If those conditions are met you should be able to retrieve client IP via the X-Forwarded-For header on the request.
I hope this helps!
Best Regards, Purnima Kumari
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.