<p>This question has been asked and answered before on stackoverflow but because I'm new to K8, I don't understand the answer.</p>

<p>Assuming I have two containers with each container in a separate POD (because I believe this is the recommend approach), I think I need to create a single service for my two pods to be apart of.</p>

<ol>
<li>How does my java application code get the IP address of the service?</li>
<li>How does my java application code get the IP addresses of another POD/container (from the service)?</li>
<li>This will be a list of IP address because these are stateless and they might be replicated. Is this correct?</li>
<li>How do I select the least busy instance of the POD to communicate with?</li>
</ol>

<p>Thanks
Siegfried</p>

<blockquote>
  <p>How does my java application code get the IP address of the service?</p>
</blockquote>

<p>You need to create a Service to expose the Pod's port and then you just need to use the Service name and kube-dns will resolve the Pod's IP address</p>

<blockquote>
  <p>How does my java application code get the IP addresses of another
  POD/container (from the service)?</p>
</blockquote>

<p>Yes, using the service's name</p>

<blockquote>
  <p>This will be a list of IP address because these are stateless and they
  might be replicated. Is this correct?</p>
</blockquote>

<p>The Service will load balance between all pods that matches the selector, so it could be 0, 1 or any number of Pods</p>

<blockquote>
  <p>How do I select the least busy instance of the POD to communicate with?</p>
</blockquote>

<p>Common way is round robin policy but here are other specific balancing policies
<a href="https://kubernetes.io/docs/concepts/services-networking/service/#proxy-mode-ipvs" rel="noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/#proxy-mode-ipvs</a></p>

<p>Cheers ;)</p>
