如何从 Kubernetes 服务背后的 HTTP 请求中读取客户端 IP 地址? [英] How to read client IP addresses from HTTP requests behind Kubernetes services?

查看:23
本文介绍了如何从 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:

  1. 使用 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".

这篇关于如何从 Kubernetes 服务背后的 HTTP 请求中读取客户端 IP 地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆