Describe the bug
I have services with ClusterIP in Kubernetes and using Nginx ingress to expose these services to the internet. When I try to get the client IP address in the application I am getting cluster's node IP. How can I retrieve real client IP?
Version of Helm and Kubernetes:
kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.4", GitCommit:"5ca598b4ba5abb89bb773071ce452e33fb66339d", GitTreeState:"clean", BuildDate:"2018-06-06T08:13:03Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.7", GitCommit:"4683545293d792934a7a7e12f2cc47d20b2dd01b", GitTreeState:"clean", BuildDate:"2019-06-06T01:39:30Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
helm version
Client: &version.Version{SemVer:"v2.9.1", GitCommit:"20adb27c7c5868466912eebdf6664e7390ebe710", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.14.2", GitCommit:"a8b13cc5ab6a7dbef0a58f5061bcc7c0c61598e7", GitTreeState:"clean"}
Which chart:
stable/nginx-ingress
How to reproduce it (as minimally and precisely as possible):
In my current settings, I am using below command to deploy helm chart:
helm install stable/nginx-ingress --name nginx \
--set rbac.create=true \
--set controller.replicaCount=2 \
--set controller.stats.enabled=true \
--set controller.metrics.enabled=true \
--set controller.service.loadBalancerIP=xx.xx.xx.xx
After that, I followed this guide to change configmap: https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/customization/custom-headers
kubectl apply -f custom-headers.yaml
kubectl apply -f configmap.yaml
custom-headers.yaml
apiVersion: v1
data:
X-Real-IP: $remote_addr
kind: ConfigMap
metadata:
name: custom-headers
configmap.yaml
apiVersion: v1
data:
proxy-set-headers: "default/custom-headers"
use-forwarded-headers: "true"
kind: ConfigMap
metadata:
name: nginx-configuration
labels:
app.kubernetes.io/name: nginx
app.kubernetes.io/part-of: nginx
Anything else we need to know:
If this is not the right way, how can I do configure helm chart to get client real IP in my application?
having the same problem. how did you do it?
@reco set service.spec.externalTrafficPolicy field to Local
https://kubernetes.io/docs/tutorials/services/source-ip/
Most helpful comment
@reco set
service.spec.externalTrafficPolicyfield toLocalhttps://kubernetes.io/docs/tutorials/services/source-ip/