I having a WebAPI Application deployed in Kubernetes and when we are accessing the API, we need to log the system IP from where the application gets accessed. In simple, I need to get the Client IP / System IP from where the API gets invoked. In order to get the IP Address, I am using
HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString()
but it is always returning the Node IP Address of Kubernetes instead of client IP Address. The Service abstraction / service that are created in Kubernetes is of type "ClusterIP".
Is it possible to get the client IP with a service of type ClusterIP?.
As per the link given by Maciek Sawicki, services of type ClusterIP, are accessible from within a cluster and hence services of type ClusterIP are not accessible outside the cluster. So the traffic to such services, come from either nodes or through other pods.
However if you want to log the IP address of the client, change the service type to NodePort or load balancer and then add service.spec.externalTrafficPolicy
to the value Local
as given in the above link.