<p>i have a question on the kubernetes DNS lookup, if i am using in my services deployment "dns" instead of "env", </p>

<p>Can my microservice using another microservices in the cluster get the dns names of all the microservices?</p>

<p>I get this piece of code, if I use <code>env</code> then I get the the info of host from env. but if I am using <code>dns</code> what format and how do I get the dns names, is there a DNS object I can query on the client side?</p>

<pre><code>if (isset($_GET['cmd']) === true) {
  $host = 'redis-master';
if (getenv('GET_HOSTS_FROM') == 'env') {
  $host = getenv('REDIS_MASTER_SERVICE_HOST');
}
</code></pre>

<p>Ref: <a href="https://github.com/GoogleCloudPlatform/container-engine-samples/blob/master/guestbook/php-redis/guestbook.php" rel="nofollow noreferrer">https://github.com/GoogleCloudPlatform/container-engine-samples/blob/master/guestbook/php-redis/guestbook.php</a></p>

<p>If someone has examples (preferably nodejs), I can dig into that. </p>

<p>First off this is <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#supported-dns-schema" rel="noreferrer">documented throughly</a>. In any case if you want to query DNS to find out where things are running you can do so if you know the service name by pointing at:</p>

<pre><code>my-svc.my-namespace.svc.cluster.local
</code></pre>

<p>Additionally, if you also want to abstract port numbers and are OK with knowing a port name you can query SRV records and get both port numbers as well as CNAME:</p>

<pre><code>_my-port-name._my-port-protocol.my-svc.my-namespace.svc.cluster.local
</code></pre>

<p>For your specific example this would be something like (assuming default namespace):</p>

<pre><code>_redis-client._tcp.redis-service.default.svc.cluster.local
</code></pre>

<p>Querying SRV records is more reliable than depending on environment variables because if during the lifetime of the pod, an external service changes location, environment variables can't be re-injected, but re-querying DNS records will yield updated results.</p>
