<p>I have to communicate between two PODs in minikube which are exposed in two different ports but are in a single node.</p>

<p>For example:</p>

<ul>
<li>POD A uses 8080 port and which is the landing page. </li>
<li>From POD A we access POD B via hyperlink which uses 8761 port. </li>
</ul>

<p>Now, in kubernetes it assigns a port dynamically eg: POD A: 30069 and POD B: 30070</p>

<p><strong>Problem here is</strong>: it does not automatically map kubernetes port for POD B (30070) while accessing POD B from POD A(30069). Instead POD B tries to   open in 8761 port.</p>

<p>Apologies if my description is confusing. Please feel free to recheck if you could not relate to my question.</p>

<p>Thanks for your help</p>

archie
<blockquote>
  <p>I have to communicate between two PODs in minikube which are exposed in two different ports but are in a single node.</p>
</blockquote>

<p>Based on the facts that you want inter-pod communication and that pods reside on the same node, you could have several (rather questionable and fragile) approaches such as hostname and nodePort exposures. In order to be more in line with kubernetes approach and recommendations I'd advise to use Service instead of exposing ports directly from Pod level.</p>

<p>You can read more about Services in <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">the official documenatation</a> and example for Service usage would be like so:</p>

<pre><code>kind: Service
apiVersion: v1
metadata:
  name: my-pod-b-service
spec:
  selector:
    app: MyPodBApp
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8761
</code></pre>

<p>This specification will create a new Service object named <code>my-pod-b-service</code> which targets TCP port 8761 on any Pod with the <code>app=MyPodBApp</code> label. With that any request coming from pod A for host: <code>my-pod-b-service</code> and port: <code>80</code> would be served by some pod B on port <code>8761</code> (note that port and targetPort can be the same, this is just an example).</p>

<p>As a side note, for pod A you would have something like:</p>

<pre><code>kind: Service
apiVersion: v1
metadata:
  name: my-pod-a-service
spec:
  selector:
    app: MyPodAApp
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
</code></pre>

<p>Since you target services, you can map same incoming port (80) to both services, and kubernetes is taking care that each comes to appropriate pods, as long as pod selector is properly set on pods.</p>
