如何从Kubernetes服务后面的HTTP请求中读取客户端IP地址? [英] How to read client IP addresses from HTTP requests behind Kubernetes services?
问题描述
我的Web应用程序作为SSL的nginx反向代理后面的Kubernetes pod运行。代理和我的应用程序都使用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根据源IP配置你的nginx以平衡并直接将流量发送到你的端点( 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 )并在服务上设置余额注释,以便使用来源。
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".
这篇关于如何从Kubernetes服务后面的HTTP请求中读取客户端IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!