<h2>The situation</h2>

<ul>
<li>I have a Spring Boot service running inside Kubernetes</li>
<li>Multiple instance are running (the kubernetes deployment has multiple replicas configured)</li>
<li>I have an incoming HTTP from outside the cluster that hits on of the instances</li>
<li>I want to relay the fact to all other instances</li>
</ul>

<h2>Question</h2>

<p>Is there an easy, no external things needed, solution to find a list of "all pods of my service" ? I think I remember that this could be possible via DNS resolution but my Google-Fu seems to weak to find something.</p>

<p>Of course I can always to this via some other solution (e.g. Redis, Kafka, whatever) but since I only need this for a one-off feature I would like to not introduce any moving parts and keep it as simple as possible.</p>

Martin Thurau
<p>Internal K8s DNS would only get you the IP-address of the service. Luckily, there is the Endpoints resource exactly for the purpose of getting the Pods that back a Service.</p>

<p>With kubectl you can check endpoints out like this: </p>

<pre><code>kubectl get endpoints nginx -o yaml
</code></pre>

<p>With this command you get hold of the Pod names:</p>

<pre><code>kubectl get endpoints nginx -o=jsonpath='{.subsets[*].addresses[*].targetRef.name}'
</code></pre>

<p>To execute the same thing from your Spring Boot app, you can try to make use of the official <a href="https://github.com/kubernetes-client/java/" rel="nofollow noreferrer">Kubernetes Java client library.</a></p>
