如何从kubernetes容器中获得公共IP

我有多个部署在kubernetes容器的实例。

容器中的应用程序需要来自pod /节点的公共IP。

从部署清单,我试图使用以下,

  • status.podIP
  • spec.nodeName

但是他们两个都返回我的节点的私有IP地址,而不是公有IP。

有人可以帮助解释status.podIP值来自哪里? 它来自节点清单吗? 或者从VM / dockerconfiguration? 任何关于如何将公共IP地址添加到我的容器中的build议?

谢谢

公共IP可能无法通过Kubernetes获得。 但是您可以使用外部服务来查询IP。

$ curl ipinfo.io/ip 

是一种可能的方法。 但他们有速度限制。 你也可以find其他的select。 下一个选项是在一个知道的机器上用下面的configuration设置一个Nginx服务器

 location = /ip { add_header Last-Modified $date_gmt; add_header Cache-Control 'private no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0'; if_modified_since off; expires off; etag off; default_type text/plain; return 200 "$remote_addr"; } 

然后用这个nginx的公共IP调用这个端点

 $ curl <publicipofnginx>/ip 

这将使机器的公众对curl的呼叫。

Kubernetes通过“负载均衡”服务暴露外部/公共IP地址(和端口)。 在大多数情况下,容器不需要知道这个外部IP地址; 他们只需要监听configuration的端口。 该服务将确保发送到外部/公共IP的stream量路由到您的(希望复制w / ReplicaSet)容器。 请查看以下Kubernetes服务示例 。