2
votes

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.

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.

My question is that:

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.

Thank you in advance.

my-ros-service.yaml

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

1 Answers

5
votes

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.