<p>I have kube-dns running in a (bare metal) cluster. I know that it works, as I can <a href="https://github.com/kubernetes/dns/blob/master/docs/specification.md" rel="noreferrer">interpolate a service to a name</a> I've created and get a host entry:</p>

<pre><code>$ host elk-service-headless.default.svc.cluster.local
elk-service-headless.default.svc.cluster.local has address 10.42.0.151
elk-service-headless.default.svc.cluster.local has address 10.42.0.152
elk-service-headless.default.svc.cluster.local has address 10.42.0.153
(...)
</code></pre>

<p>What I can't figure out how to do is to list all of the records that kube-dns is holding. I've tried the <a href="https://stackoverflow.com/questions/19322962/how-can-i-list-all-dns-records">standard DNS tricks</a> like dig and <code>host -l</code> and can't get them. But in any case, there must be a way to do this from Kubernetes itself. I tried inspecting ConfigMaps and didn't find what I'm looking for.</p>

tedder42
<p>This post will help you find the internal DNS record of your K8s services on a cluster that runs kube-dns:</p>
<ol>
<li>Find the ClusterIP of the kube-dns service:</li>
</ol>
<p><code>kubectl -n kube-system get svc kube-dns</code></p>
<p><a href="https://i.stack.imgur.com/LocI9.png" rel="noreferrer"><img src="https://i.stack.imgur.com/LocI9.png" alt="enter image description here" /></a></p>
<p>Now we know the internal K8s DNS resolver IP is 172.20.0.10</p>
<ol start="2">
<li>Find the application service endpoint IP:</li>
</ol>
<p><code>kubectl -n fe get ep</code></p>
<p><a href="https://i.stack.imgur.com/Ce7aC.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Ce7aC.png" alt="enter image description here" /></a></p>
<ol start="3">
<li>Exec into the application pod:</li>
</ol>
<p><code>kubectl -n fe exec -it fe-app-575fdf6cb6-lt7t6 -- sh</code></p>
<ol start="4">
<li>Get DNS service name:</li>
</ol>
<p><a href="https://i.stack.imgur.com/dzXUd.png" rel="noreferrer"><img src="https://i.stack.imgur.com/dzXUd.png" alt="enter image description here" /></a></p>
<ol start="5">
<li>A script to list all the K8s SVC DNS records:</li>
</ol>
<pre><code>#!/bin/bash

echo =========== Create an ubuntu pod ==================
kubectl run ubuntu --image=ubuntu -- bash -c &quot;while true; do echo hello; sleep 10;done&quot;

# Wait for the pod &quot;ubuntu&quot; to contain the status condition of type &quot;Ready&quot;
kubectl wait --for=condition=Ready pod/ubuntu

# Save a sorted list of IPs of all of the k8s SVCs:
kubectl get svc -A|egrep -v 'CLUSTER-IP|None'|awk '{print $4}'|sort -V &gt; ips

# Copy the ip list to owr Ubuntu pod:
kubectl cp ips ubuntu:/

echo =========== Installing dig tool into the pod ===============
kubectl exec -it ubuntu -- apt-get update
kubectl exec -it ubuntu -- apt install -y dnsutils

# Print 7 blank lines
yes '' | sed 7q
echo =========== Print all k8s SVC DNS records ====================
for ip in $(cat ips); do echo -n &quot;$ip &quot;; kubectl exec -it ubuntu -- dig -x $ip +short; done
echo ====== End of list =====================

echo ========= Cleanup  ===============
kubectl delete po ubuntu
rm ips
exit 0
</code></pre>
