<p>I have a node with 2 pods. Each pod will need to speak to each other. Problem being that i do not want to hardcode the IPs in for the communication. </p>

<p>Similar to a DNS service, i need something (that does not change) that can sit above the pod ip and allow me to still communicate between the pods.</p>

<p>I can see two solution</p>

<p><strong>Solution 1:</strong> Use Service</p>

<p>If they are not from same controller and if they have their own Service, they can use Service to communicate with each other.</p>

<pre><code>Service 1 - &gt; Pod 1
Service 2 - &gt; Pod 2
</code></pre>

<p>Use this Service</p>

<pre><code>Pod 1: Service 2 -&gt; Pod 2
Pod 2: Service 1 -&gt; Pod 1
</code></pre>

<p><strong>Solution 2:</strong> Use StatefulSet</p>

<p>If they need same Controller, you can use <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="noreferrer">StatefulSet</a>. </p>

<blockquote>
  <p>For a StatefulSet with N replicas, each Pod in the StatefulSet will be assigned an integer ordinal, in the range [0,N], that is unique over the Set</p>
</blockquote>

<p>That means Pod name will be: <code>$(statefulset name)-$(ordinal)</code></p>

<p>If you have StatefulSet named <code>nginx</code> with replica 2, you will have two Pod <code>nginx-0</code> &amp; <code>nginx-1</code>.</p>

<blockquote>
  <p>As each Pod is created, it gets a matching DNS subdomain, taking the form: <code>$(podname).$(governing service domain)</code></p>
</blockquote>

<p><strong>Pod <code>nginx-0</code>:</strong> <code>nginx-1.{service-account}.{namespace}.svc.cluster.local</code> -> <strong><code>nginx-1</code></strong></p>

<p><strong>Pod <code>nginx-1</code>:</strong> <code>nginx-0.{service-account}.{namespace}.svc.cluster.local</code> -> <strong><code>nginx-0</code></strong></p>

<p>Using this <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#stable-network-id" rel="noreferrer">Stable Network ID</a>, these Pods can communicate with each other.</p>
