<p>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.</p>

<p>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. </p>

<p>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. </p>

<p>My question is that:</p>

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

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

<p>Any advice or information you could provide would be greatly appreciated.</p>

<p>Thank you in advance.</p>

<p>my-ros-service.yaml</p>

<pre><code>kind: Service
apiVersion: v1beta1
id: my-ros-service
port: 11311
selector:
  name: my-ros
containerPort: 11311
createExternalLoadBalancer: true
</code></pre>

<p>I don't think there is currently a better solution than what you are doing.  There is already a related issue, <a href="https://github.com/GoogleCloudPlatform/kubernetes/issues/1802" rel="noreferrer">kubernetes issue 1802</a>, 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.</p>
