Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access client IP of an HTTP request from Google Container Engine?

I'm running a gunicorn+flask service in a docker container with Google Container Engine. I set up the cluster following the tutorial at http://kubernetes.io/docs/hellonode/

The REMOTE_ADDR environmental variable always contains an internal address in the Kubernetes cluster. What I was looking for is HTTP_X_FORWARDED_FOR but it's missing from the request headers. Is it possible to configure the service to retain the external client ip in the requests?

like image 989
Vik Avatar asked Dec 14 '22 07:12

Vik


1 Answers

If anyone gets stuck on this there is a better approach. You can use the following annotations depending on your kubernetes version:

service.spec.externalTrafficPolicy: Local 

on 1.7

or

service.beta.kubernetes.io/external-traffic: OnlyLocal

on 1.5-1.6

before this is not supported

source: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/

note that there are caveats: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#caveats-and-limitations-when-preserving-source-ips

like image 196
Arnaud Moret Avatar answered Dec 31 '22 17:12

Arnaud Moret