Is it possible for me to get a log which shows the source IP of requests hitting a NodePort in my Kubernetes cluster?

10/28/2019

I have a container with an exposed port in a pod. When I check the log in the containerized app, the source of the requests is always 192.168.189.0 which is a cluster IP. I need to be able to see the original source IP of the request. Is there any way to do this? I tried modifying the service (externalTrafficPolicy: Local) instead of Cluster but it still doesn't work. Please help.

-- Ibrahim Jimoh
kubernetes

1 Answer

10/28/2019

When you are working on an application or service that needs to know the source IP address you need to know the topology of the network you are using. This means that you need to know how the different layers of loadbalancers or proxies works to deliver the traffic to your service.

Depending on what cloud provider you are using or the loadbalancer you have in front of your application the source IP address should be on a header of the request. The header you have to look for is X-Fordwared-for, more info here, depending on the proxy or loadbalancer you are using sometimes you need to activate this header to receive the correct IP address.

-- wolmi
Source: StackOverflow