How to read client IP addresses from HTTP requests behind Kubernetes services?

前端 未结 7 1138
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 01:03

my web application is running as a Kubernetes pod behind an nginx reverse proxy for SSL. Both the proxy and my application use Kubernetes services for load balancing (as des

7条回答
  •  长情又很酷
    2020-12-03 02:04

    As of 1.5, if you are running in GCE (by extension GKE) or AWS, you simply need to add an annotation to your Service to make HTTP source preservation work.

    ...
    kind: Service
    metadata:
      annotations:
        service.beta.kubernetes.io/external-traffic: OnlyLocal
    ...
    

    It basically exposes the service directly via nodeports instead of providing a proxy--by exposing a health probe on each node, the load balancer can determine which nodes to route traffic to.

    In 1.7, this config has become GA, so you can set "externalTrafficPolicy": "Local" on your Service spec.

    Click here to learn more

提交回复
热议问题