<p>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</p>

<pre><code>HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() 
</code></pre>

<p>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". </p>

<p>Is it possible to get the client IP with a service of type ClusterIP?.</p>

user2003780
<p>As per the <a href="https://kubernetes.io/docs/tutorials/services/source-ip/" rel="nofollow noreferrer">link</a> given by <a href="https://stackoverflow.com/users/201306/maciek-sawicki">Maciek Sawicki</a>, 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.</p>

<p>However if you want to log the IP address of the client, change the service type to NodePort or load balancer and then add <code>service.spec.externalTrafficPolicy</code> to the value <code>Local</code> as given in the above link.</p>
