[英]How to get the clients external ip, im using Gcloud/kubernetes
我最近开始在gcloud上使用kubernetes,到目前为止到目前为止还算顺利,但是我似乎无法使用wildfly(jsf)在我的应用程序上获取客户端/用户的外部IP地址 ,因此不胜感激! 我使用以下命令公开我的Pod:
kubectl expose rc modcluster-replication-controller --name=modcluster --type="LoadBalancer"
我基于票务怪兽Kubernetes 使用kubernetes,gcloud,modcluster, wildfly
我的建议(如果您的应用程序是端口80/443上的HTTP / HTTP)是利用Ingress控制器,该控制器基本上将服务作为HTTP / HTTPs负载平衡器公开,从而在数据包中注入X-Forwarded-For。
这将显示源/客户端的IP地址。 请按照此处的X-Forwarded-For字段上的教程详细信息进行操作。
我刚刚在该教程中测试过的示例调用: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
k8s 1.7版(仅在1.7.2中进行了测试)使此操作变得轻而易举。 只需在您的LoadBalancer服务中使用spec:externalTrafficPolicy:Local。 它将为端口80和443提供服务,没有任何问题。 例如:
apiVersion: v1
kind: Service
metadata:
name: myservice
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
name: http
- port: 443
protocol: TCP
targetPort: 443
name: https
selector:
app: myapp
role: myrole
type: LoadBalancer
loadBalancerIP: 104.196.208.195
externalTrafficPolicy: Local
kubectl describe svc servicename | grep 'LoadBalancer Ingress'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.