如何使用Google Container Engine上的Kubernetes服务公开动态端口? [英] How to expose dynamic ports using Kubernetes service on Google Container Engine?

查看:88
本文介绍了如何使用Google Container Engine上的Kubernetes服务公开动态端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过TCP协议通过互联网从本地计算机连接到Google Container Engine(GKE)上的Docker容器.到目前为止,我已经使用了提供外部IP地址的Kubernetes服务,因此本地计算机可以使用该服务连接到GKE上的容器.创建服务时,我们只能指定一个端口,而不能指定端口范围.请参阅下面的my-ros-service.yaml.在这种情况下,我们可以通过GCE外部的11311端口访问容器.

I am trying to connect to a Docker container on Google Container Engine(GKE) from my local machine through the internet by TCP protocol. So far I have used Kubernetes services which gives an external IP address, so the local machine can connect to the container on GKE using the service. When we create a service, we can specify only one port and cannot specify the port range. Please see the my-ros-service.yaml below. In this case, we can access the container by 11311 port from outside of GCE.

但是,在我的容器上运行的某些应用程序公开了动态端口以连接到其他应用程序.因此,在运行应用程序之前,我无法确定应用程序使用的端口号,也无法创建Kubernetes服务.

However, some applications that run on my container expose dynamic ports to connect to other applications. Therefore I cannot determine the port number that the application uses and cannot create the Kubernetes services before I run the application.

到目前为止,我已经通过在运行应用程序时创建许多具有不同端口的服务来设法连接到容器.但这不是解决问题的现实方法.

So far I have managed to connect to the container by creating many services which have different port while running the application. But this is not a realistic way to solve the problem.

我的问题是:

如何使用Kubernetes服务连接到从GCE外部公开Docker容器上动态端口的应用程序?

How to connect to the application that exposes dynamic ports on Docker container from outside of the GCE by using Kubernetes service?

如果可能的话,我们可以在运行在容器上运行的应用程序之前创建一个为传入连接公开动态端口的服务吗?

If possible, can we create a service which exposes dynamic port for incoming connection before running the application which runs on the container?

我们将不胜感激您提供的任何建议或信息.

Any advice or information you could provide would be greatly appreciated.

谢谢.

my-ros-service.yaml

my-ros-service.yaml

kind: Service
apiVersion: v1beta1
id: my-ros-service
port: 11311
selector:
  name: my-ros
containerPort: 11311
createExternalLoadBalancer: true

推荐答案

我认为目前没有比您正在做的更好的解决方案. kubernetes问题1802 已经存在一个与每个服务具有多个端口有关的问题.我提到了您对此问题的要求.您可能想在此跟进有关用例的更多信息,例如您正在运行的程序(如果它是公开可用的)以及动态端口是否来自特定的连续范围.

I don't think there is currently a better solution than what you are doing. There is already a related issue, kubernetes issue 1802, about having multiple ports per service. I mentioned your requirements on that issue. You might want to follow up there with more information about your use case, such as what program you are running (if it is publicly available), and whether the dynamic ports come from a specific contiguous range.

这篇关于如何使用Google Container Engine上的Kubernetes服务公开动态端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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