<p>We have Kubernetes cluster where each service has 3 pod running.
we got a use case where i want each pod knows the ip of other pods.</p>
<pre><code>For Example:
P1 --&gt; this pod should know ip of itself, p2, p3 pod ip's 
P2 --&gt; this pod should know ip of itself, p1, p3 pod ip's 
p3 --&gt; this pod should know ip of itself, p2, p3 pod ip's 
</code></pre>
<hr />
<p>I found this on google but looks like we only get IP of pod itself it won't give the ip of other two pod running.</p>
<pre><code>          - name: POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
</code></pre>
<hr />
<p>Is there a way i can get this info in my java code?</p>

Mohit Singh
<p>Using env as you mentioned might not suffice as pods are supposed to be temporary resources and get added and deleted.</p>
<p>But below command can fetch you the values</p>
<pre class="lang-sh prettyprint-override"><code>$kubectl get pods -o=jsonpath=&quot;{range .items[*]}{.status.podIP}{','}{end}&quot;
</code></pre>
<p>You did not mention if the pods belong to the same service but if that is the case(which I think), you could use <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api" rel="nofollow noreferrer">Selectors</a></p>
<pre class="lang-sh prettyprint-override"><code>$kubectl get pods -l=&quot;app=my-service&quot; -o=jsonpath=&quot;{range .items[*]}{.status.podIP}{','}{end}&quot;
x.y.z.a,b.c.d.e,
</code></pre>
<p>Here the two IPs are x.y.z.a and b.c.d.e</p>
<p>You should be able to find equivalent in the corresponding language(java) api libraries</p>
<p>If you are okay to be able to let the request go to any pod, you can look at <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/" rel="nofollow noreferrer">Kube DNS</a></p>
