Kubernetes DNS On-Call: Six Broken Lookups
You're on call for the platform team at a small online shop. Six DNS tickets are waiting. Each one is a real problem in the cluster in front of you.
This lab tests what you know. It doesn't teach the theory. If a term is new to you, read the companion post, How DNS works in Kubernetes. Each ticket links to the section you need, and the official DNS for Services and Pods and Customizing DNS Service pages are fair game too.
How a ticket works
- Read the message from the person who opened the ticket.
- Do the steps under See the problem. They show you what's broken, so you have something to compare with later.
- Read the Done when line. It says exactly what the lab checks.
- Investigate and fix the problem, any way you like.
- The lab checks the cluster every few seconds and closes the ticket by itself when it's fixed.
Tickets unlock one at a time, in order. If you get stuck, open the Nudge first, and the Solution only if you need it.
Where things run
Every command runs in the terminal: the cplane-01 tab. kubectl is set up
with admin access. The cluster has two nodes, cplane-01 and node-01, and Pods run on both.
The dnsutils Pod in the default namespace is your test client. It has dig, nslookup, host and getent:
kubectl exec dnsutils -- dig +short kubernetes.default.svc.cluster.local
💡 Give the cluster two or three minutes after it starts. The first ticket unlocks when everything is ready.
The Cluster You're On Call For
| Namespace | What runs there |
|---|---|
kube-system | CoreDNS (Deployment coredns, Service kube-dns) and the rest of a kubeadm control plane |
observability | collector, a Service that receives telemetry, and node-agent, a DaemonSet on every node that sends it |
data | db, a two-member StatefulSet with a headless Service |
infra | corp-dns, the company's own DNS server for the corp.internal zone, at 10.96.200.53 |
shop | checkout, the shop's payment service |
Your tools: kubectl, the dnsutils Pod, and CoreDNS's own logs:
kubectl -n kube-system logs -l k8s-app=kube-dns --tail=20
Ticket 1: "Nothing resolves"
From: Tomás, platform team
I did a label cleanup in
kube-systemthis morning. Since then, every app is timing out on DNS, even for names inside the cluster. CoreDNS itself looks healthy. Help!
See the problem. In the terminal:
kubectl exec dnsutils -- nslookup kubernetes.default
kubectl -n kube-system get pods -l k8s-app=kube-dns
The lookup hangs for about 15 seconds and ends with ;; connection timed out; no servers could be reached.
The CoreDNS Pods are 1/1 Running.
Done when: the kube-dns Service has ready endpoints, and the lookup above returns 10.96.0.1.
Theory: who answers and the debugging checklist.
Nudge
Pods don't talk to the CoreDNS Pods directly. Follow the path: the nameserver line in a Pod's
/etc/resolv.conf, the Service with that IP, and that Service's endpoints. In the terminal:
kubectl -n kube-system get endpointslice -l kubernetes.io/service-name=kube-dns
Solution
The kube-dns Service selects k8s-app: coredns, but the CoreDNS Pods are labelled k8s-app: kube-dns. In the
terminal:
kubectl -n kube-system get pods -l k8s-app=kube-dns --show-labels
kubectl -n kube-system patch svc kube-dns --type=merge -p '{"spec":{"selector":{"k8s-app":"kube-dns"}}}'
Ticket 2: "Our names work, the internet's don't"
From: Grace, payments developer
Since Ticket 1 was fixed, my Pods can find other Services again. But installing packages from
pypi.orgfails with a DNS error. The node itself resolvespypi.orgfine.
See the problem. In the terminal:
kubectl exec dnsutils -- nslookup pypi.org
kubectl -n kube-system logs -l k8s-app=kube-dns --tail=5
The lookup fails with ** server can't find pypi.org: SERVFAIL, and CoreDNS logs i/o timeout errors.
Done when: every CoreDNS Pod answers both pypi.org and kubernetes.default.svc.cluster.local.
Theory: inside CoreDNS.
Nudge
Read the error lines in the CoreDNS logs: which address are the failing queries sent to? Then find where that address comes from. In the terminal:
kubectl -n kube-system get configmap coredns -o jsonpath='{.data.Corefile}'
Solution
The Corefile forwards to 10.96.0.253, where nothing listens. Change the line back to
forward . /etc/resolv.conf. In the terminal:
kubectl -n kube-system edit configmap coredns
The reload plugin picks up the change within 1-3 minutes. Watch for Reloading complete in the logs.
Ticket 3: "The node agent can't find the collector"
From: Kenji, observability team
node-agentruns on every node withhostNetwork: true, because it reads the node's network stats. It sends them tocollector.observability, but it can't resolve that name. Other Pods can. It must stay on the host network.
See the problem. In the terminal:
kubectl -n observability exec ds/node-agent -- nslookup collector.observability
kubectl exec dnsutils -- nslookup collector.observability
From the agent you get ** server can't find collector.observability: NXDOMAIN. From dnsutils, the name
resolves.
Done when: every node-agent Pod resolves collector.observability, and the DaemonSet still uses
hostNetwork: true.
Theory: choosing a DNS policy.
Nudge
Compare the two Pods' resolver files. In the terminal:
kubectl -n observability exec ds/node-agent -- cat /etc/resolv.conf
kubectl exec dnsutils -- cat /etc/resolv.conf
Then look at the agent's dnsPolicy, and read what the docs say about it for host-network Pods.
Solution
In the terminal:
kubectl -n observability patch ds node-agent --type=merge \
-p '{"spec":{"template":{"spec":{"dnsPolicy":"ClusterFirstWithHostNet"}}}}'
kubectl -n observability rollout status ds/node-agent
Ticket 4: "The database never becomes ready"
From: Olu, data team
dbis a two-member StatefulSet. Before a member reports ready, it checks that it can resolve both members by name:db-0.db.data.svc.cluster.localanddb-1.db.data.svc.cluster.local. Both Pods are running, but they've been0/1forever. We need that readiness check, so please don't remove it.
See the problem. In the terminal:
kubectl -n data get pods
kubectl -n data exec db-0 -- nslookup db-1.db.data.svc.cluster.local
Both Pods are 0/1 Running, and the lookup returns ** server can't find db-1.db.data.svc.cluster.local: NXDOMAIN.
Done when: both db Pods are 1/1 Ready, with the readiness probe unchanged and db still a headless Service.
Theory: what gets a name.
Nudge
The names db-0.db... exist only while something is true about the Pods. What, and what are these Pods
waiting for? The Service's spec has a field for exactly this case. In the terminal:
kubectl explain service.spec --recursive | grep -i ready
Solution
In the terminal:
kubectl -n data patch svc db --type=merge -p '{"spec":{"publishNotReadyAddresses":true}}'
kubectl -n data get pods -w
Ticket 5: "We need the corporate names"
From: Priya, IT
Our internal names, such as
wiki.corp.internalandgit.corp.internal, are served by our own DNS server. It now runs in the cluster as thecorp-dnsService ininfra, at10.96.200.53. Please make those names resolve from every Pod, without changing the Pods. Everything else must keep working.
See the problem. In the terminal:
kubectl exec dnsutils -- dig wiki.corp.internal
kubectl exec dnsutils -- dig +short @10.96.200.53 wiki.corp.internal
Through cluster DNS, the status is NXDOMAIN. Asked directly, corp-dns answers 192.0.2.10.
Done when: every CoreDNS Pod answers wiki.corp.internal with 192.0.2.10 and git.corp.internal with
192.0.2.11, and still answers pypi.org.
Theory: inside CoreDNS.
Nudge
Look at the official stub domain example,
and add a block like it to the coredns ConfigMap. After every edit, wait and read the logs:
kubectl -n kube-system logs -l k8s-app=kube-dns --since=3m | grep -i reload
Solution
Add this block at the end of the Corefile, after the closing } of the .:53 block. Use the IP: CoreDNS
can't use a DNS name as a forward target here. In the terminal:
kubectl -n kube-system edit configmap coredns
corp.internal:53 {
errors
cache 30
forward . 10.96.200.53
}
Wait for Reloading complete from both Pods, then test with kubectl exec dnsutils -- dig +short wiki.corp.internal.
Ticket 6: "Three wasted lookups per call"
From: Ravi, SRE
checkoutcallsapi.github.comall day. I turned on CoreDNS query logging: before each real lookup, the Pod first asks forapi.github.com.shop.svc.cluster.local, then.svc.cluster.local, then.cluster.local, and getsNXDOMAINthree times. Make checkout look upapi.github.comdirectly. Rules: don't change the app, don't usednsPolicy: Default, andcheckoutmust still reachcollector.observabilityby that short name.
See the problem. In the terminal:
kubectl -n shop exec deploy/checkout -- cat /etc/resolv.conf
The last line is options ndots:5.
Done when: both checkout Pods run with ndots of 2 or less, and inside each Pod getent hosts resolves
both api.github.com and collector.observability.
Theory: how a short name becomes a full one.
Nudge
A Pod's dnsConfig.options can override ndots while the policy stays ClusterFirst. Count the dots in each
name the ticket mentions. Then test your choice from inside a checkout Pod with getent hosts, which uses the
same resolver library as the app, not with dig.
Solution
In the terminal:
kubectl -n shop patch deploy checkout --type=merge \
-p '{"spec":{"template":{"spec":{"dnsConfig":{"options":[{"name":"ndots","value":"2"}]}}}}}'
kubectl -n shop rollout status deploy/checkout
kubectl -n shop exec deploy/checkout -- getent hosts collector.observability
kubectl -n shop exec deploy/checkout -- getent hosts api.github.com
ndots:1 would break collector.observability on this Alpine-based image.
Shift Report
| Ticket | Where the fault was | The trap |
|---|---|---|
| 1. Nothing resolves | The kube-dns Service | Healthy CoreDNS Pods behind a Service that selects nothing |
| 2. No internet names | forward in the Corefile | Cluster names keep working, so it looks like an app problem |
| 3. Node agent | The Pod's DNS policy | hostNetwork silently swaps ClusterFirst for Default |
| 4. Database deadlock | The headless Service | Not-ready Pods have no DNS names |
| 5. Corporate names | A stub domain | A failed reload keeps the old config, without any other sign |
| 6. Wasted lookups | ndots | musl doesn't fall back to the search list |