<p>I have a Pod <code>my-pod-1</code> and a TCP server listening on a dynamically assigned port <code>12345</code> (the server then registers the port to other services). I know I could create a Service for the server, so that clients on other Pods can connect to it, but because the port is dynamically assigned, it is inconvenient. What I am thinking about is that, can other Pods reach out to the server through <code>my-pod-1:12345</code> directly? What is the problem with this approach?</p>

Dagang
<p>I am not sure if you can do <code>&lt;pod-name&gt;:&lt;port&gt;</code>.  You could setup a Route to use an alias for your service, but the dynamically assigned port seems to prevent this... Unless you were to setup some service on a consistent port (8080?) that would return information regarding services -> assigned ports? That could very well be a terrible idea, just off the top of my head.</p>

<p>I do know that you can do <code>&lt;pod-IP&gt;:&lt;port&gt;</code> directly. You can use a central registry (have used Hazelcast for this) to register each service's name, IP address, port, status, and other needed data.  Link: <a href="https://hazelcast.org/" rel="nofollow noreferrer">https://hazelcast.org/</a></p>

<p>You can configure the <code>pod-IP</code>, <code>port</code> and other information as environment variables on the pod via the Downward API: <a href="https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/</a></p>
