我最近开始在 gcloud 上使用 kubernetes,到目前为止非常顺利,但我似乎无法获得 客户/用户外部IP地址在我使用 wildfly(jsf) 的应用程序上,任何想法都将不胜感激!
我使用以下命令公开我的 pod:kubectl expose rc modcluster-replication-controller --name=modcluster --type="LoadBalancer"
我正在使用 kubernetes、gcloud、modcluster、wildfly 基于 Ticket-monster Kubernetes
最佳答案
我的建议(如果您的应用程序是端口 80/443 上的 HTTP/HTTPS)是
利用基本上公开的 Ingress Controller
服务作为 HTTP/HTTPs 负载平衡器,在数据包中注入(inject) X-Forwarded-For。
这将显示源/客户端的 IP 地址。请关注tutorial
X-Forwarded-For 字段的详细信息可用 here
我刚刚使用该教程测试的示例调用:
LB IP:130.211.10.191
容器内的tcpdump:$ tcpdump -n -l -w - | strings
Output:
Host: 130.211.10.191
Cache-Control: max-age=0
Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; CrOS x86_64 7978.74.0) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/50.0.2661.103 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
If-None-Match: "574da256-264"
If-Modified-Since: Tue, 31 May 2016 14:40:22 GMT
X-Cloud-Trace-Context:
6b36a7d93d60dc6921417796255466d5/14093000126457324029
Via: 1.1 google
X-Forwarded-For: 81.47.XXX.XXX, 130.211.10.191 # the IP starting with
81. is my local IP
X-Forwarded-Proto: http
Connection: Keep-Alive
JxHTTP/1.1 304 Not Modified
关于networking - 如何获取客户端外部 ip,我使用 Gcloud/kubernetes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38077169/