简体   繁体   中英

How to get client IP address from inside a Azure Kubernetes with a ClusterIP service

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM