<p>I created a service, which has 3 pods assigned. </p>

<p><a href="https://i.stack.imgur.com/pOX5I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pOX5I.png" alt="enter image description here"></a></p>

<p>I would like to access the service through its hostname by an other service in the same project. How can I do that?</p>

<p>Tried:</p>

<pre><code>alxtbk@dns-test:~$ ping elassandra-0.elassandra
ping: elassandra-0.elassandra: Name or service not known

alxtbk@dns-test:~$ ping elassandra-0.default.svc.cluster.local
ping: elassandra-0.default.svc.cluster.local: Name or service not known

alxtbk@dns-test:~$ ping elassandra.default.svc.cluster.local
ping: elassandra.default.svc.cluster.local: Name or service not known
</code></pre>

<p>What is the correct way to resolve the ip adresses of the headless service?</p>

Alex Tbk
<blockquote>
<p>For such Services, a cluster IP is not allocated, kube-proxy does not
handle these services, and there is no load balancing or proxying done
by the platform for them. How DNS is automatically configured depends
on whether the service has selectors defined.</p>
<p><strong>With selectors</strong></p>
<p>For headless services that define selectors, the endpoints controller
creates Endpoints records in the API, and modifies the DNS
configuration to return A records (addresses) that point directly to
the Pods backing the Service.</p>
<p><strong>Without selectors</strong></p>
<p>For headless services that do not define selectors, the endpoints
controller does not create Endpoints records. However, the DNS system
looks for and configures either:</p>
<p>CNAME records for ExternalName-type services.</p>
<p>A records for any Endpoints that share a name with the service, for all other types.</p>
</blockquote>
<p>so you maybe be able to do:</p>
<pre><code>kubectl get ep
</code></pre>
<p>to get the endpoints and then use them inside another kubernetes service.</p>
