I have services with ClusterIP in Kubernetes and using nginx
(https://github.com/helm/charts/tree/master/stable/nginx-ingress) to expose these services to the internet. When I try to get client IP address in application I am getting cluster's node IP. How can I retrieve actual client IP?
I looked into "externalTrafficPolicy": "Local"
settings in service but for that service type must be LoadBalancer
.
I also tried update ingress annotations with:
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-headers: "DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,X-Forwarded-For,csrf-token"
nginx.ingress.kubernetes.io/cors-allow-origin: "https://example.com"
But, still, it's not working. Please advice!
This is unfortunately not possible today. Please see https://github.com/kubernetes/kubernetes/issues/67202 and https://github.com/kubernetes/kubernetes/issues/69811 for more discussion around this.
If you want to get the client IP address, you'll need to use NodePort
or LoadBalancer
types.