如何找出负载均衡器服务的外部IP? [英] How do I find out the external IP of a Load Balancer service?

查看:274
本文介绍了如何找出负载均衡器服务的外部IP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Google Cloud Platform上使用Kubernetes Engine.我有一个在Docker临时容器中运行进程的Pod.我还有一个负载平衡器服务,可让我从外界访问Pod.

I am using Kubernetes Engine on the Google Cloud Platform. I have a pod running a process in a Docker scratch container. I also have a load balancer service that gives me access to the pod from the outside world.

在pod中运行的进程需要知道其外部IP地址是什么.我怎么能得到这个?

The process running in the pod needs to know what its external IP address is. How can I get this?

在使用Kubernetes Engine之前,我正在使用Compute Engine,并且可以通过以下方式找到外部IP地址:

Prior to using Kubernetes Engine I was using Compute Engine and could find the external IP address by the following:

curl -H "Metadata-Flavor: Google" http://metadata/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip

我可以使用任何内部工具吗?还是我需要调用可镜像IP地址的外部站点的过程?

Are there any internal tools I can use that would be available to my process? Or would I need the process to call an external site that can mirror back the IP address?

推荐答案

每个Pod(除非配置为不这样做)在/var/run/secrets/kubernetes.io/servicetoken/token

Every Pod (unless configured not to do so) has valid kubernetes credentials in /var/run/secrets/kubernetes.io/servicetoken/token as described here so the answer is to use the kubernetes API to ask the Service in front of the Pod(s) for its status:loadBalancer:ingress:ip: as described here which I have every reason to believe GKE will keep up-to-date with any changes to the load balancer. The kubernetes API is always(?) located at https://kubernetes (that's normally enough, or https://kubernetes.default.svc.cluster.local is its full name), so there should be very little configuration the Pod would need in order to carry out the lookup.

该响应的星号是,必须向位于它前面的服务Pod提供服务的名称,因为(在大多数情况下)Pod无法知道如何许多服务都指向它.

The asterisk to that response is that one must provide the name of the Service to the Pod(s) of the Service sitting in front of it, because (for the most part) there is no way for the Pod to know how many Services point to it.

这篇关于如何找出负载均衡器服务的外部IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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