<p>What is the recommended way to communicate between the pods belonging to the same replica-set (deployment)? Is it possible to lookup what are the urls of other pods from a given pod?</p>
<p>Or is replica-set not a right approach to follow for that?</p>
<p>Looking for a right k8s way to do this. Thanks!</p>

user31986
<p>You can use a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="noreferrer">StatefulSet</a> in conjunction with a <a href="https://kubernetes.io/docs/concepts/services-networking/service/#headless-services" rel="noreferrer">Headless Service</a>.  One of the features of a StatefulSet is a unique consistent naming convention:</p>
<blockquote>
<p>For a StatefulSet with N replicas, each Pod in the StatefulSet will be
assigned an integer ordinal, from 0 up through N-1, that is unique
over the Set.</p>
</blockquote>
<p>So, if you have three copies of MyPod, you know the names will be <code>MyPod-0</code>, <code>MyPod-1</code>, <code>MyPod-2</code>.  Then if you tie them to a Headless Service called <code>MyHeadlessService</code>, you will be able to reach your pods via:</p>
<pre><code>MyPod-0.MyHeadlessService
MyPod-1.MyHeadlessService
MyPod-2.MyHeadlessService
</code></pre>
<p>To see this you can exec into <code>MyPod-0</code></p>
<pre><code>kubectl exec -it MyPod-0 /bin/bash
</code></pre>
<p>And then ping <code>MyPod-1</code></p>
<pre><code>ping MyPod-1.MyHeadlessService
</code></pre>
<p>There's lots of examples online of this pattern, and you can decide if it fits your use case.  As an anecdote, Cluster related technologies like ElasticSearch and Vault use this pattern for inter-node communication.</p>
