Does anyone know if and how I can access the origin IP-Address of the client originally performed the request if I have a LoadBalancer service in OpenShift? It is overwritten by the Load-Balancer's IP-Address.
There should be a way to access that information - may be in the optional TCP data or so. Does anyone know?
Or maybe I can use a different approach to forward the package without losing that information but still being able to scale the service to multiple Pod's. Thank you for any hint!
Best regards, Dominic
OpenShift Master: v3.9.41 Kubernetes Master: v1.9.1
IP addresses are source NAT'ed by default in Kubernetes services as of K8s 1.5, so you won't see the source IP. For LoadBalancer
type of service you can set in its spec the externalTrafficPolicy
field to Local
to preserve the source IP address:
$ kubectl patch svc yourservice -p '{"spec":{"externalTrafficPolicy":"Local"}}'
It should work out the box for the GCE and Azure cloud providers. For others follow the 'Cross platform support' section here.
Quoted from the docs:
As of Kubernetes 1.5, support for source IP preservation through Services with Type=LoadBalancer is only implemented in a subset of cloudproviders (GCP and Azure).
Note that when you set the externalTrafficPolicy
field to Local
, only the nodes where your pod is running will show as healthy because they are ones replying to your service.
OpenShift uses the same Kubernetes Service syntax.