如何从 Kubernetes 服务背后的 HTTP 请求中读取客户端 IP 地址?
我的 Web 应用程序作为 Kubernetes pod 在 SSL 的 nginx 反向代理后面运行.代理和我的应用程序都使用 Kubernetes 服务进行负载平衡(如此处所述).
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 described here).
问题是我所有的 HTTP 请求日志只显示内部集群 IP 地址,而不是实际 HTTP 客户端的地址.有没有办法让 Kubernetes 服务将此信息传递给我的应用服务器?
The problem is that all of my HTTP request logs only show the internal cluster IP addresses instead of the addresses of the actual HTTP clients. Is there a way to make Kubernetes services pass this information to my app servers?
你可以通过两种方式让 kube-proxy 完全脱离循环:
You can get kube-proxy out of the loop entirely in 2 ways:
使用 Ingress 配置您的 nginx 以根据源 ip 进行平衡并将流量直接发送到您的端点 (https://github.com/kubernetes/contrib/tree/master/ingress/controllers#ingress-controllers)
部署 haproxy serviceloadbalancer(https://github.com/kubernetes/contrib/blob/master/service-loadbalancer/service_loadbalancer.go#L51) 并在服务上设置 balance 注释,以便它使用源".
Deploy the haproxy serviceloadbalancer(https://github.com/kubernetes/contrib/blob/master/service-loadbalancer/service_loadbalancer.go#L51) and set the balance annotation on the serivce so it uses "source".