HAMZA KAREEM / CONCEPTS hamzawi.dev

Lesson 1382 min read

Kubernetes DNS ndots:5

Why Your Pod Sends 10 DNS Queries To Reach One API

Cloud infrastructurecloud infrastructure / Kubernetes & networking

Start with the mental model

Think of DNS inside a pod as a receptionist with a list of places to try. You say "payments". She doesn't know where that is, so she tries each entry on her list in order, in the building first, and only calls the outside world last.

That list is real. Cat it inside any pod:

cat /etc/resolv.conf
search myns.svc.cluster.local svc.cluster.local cluster.local
nameserver 10.96.0.10
options ndots:5

So "payments" becomes, in order:

payments.myns.svc.cluster.local → hit ✅

Lovely. That's the whole point — short names work inside a namespace.

Where the analogy breaks down (the intermediate part)

The receptionist doesn't only do this for short names. She does it for anything with FEWER THAN ndots dots. ndots:5 is absurdly high, and almost nothing has 5 dots.

So api.stripe.com (2 dots < 5) is treated as a local name first:

api.stripe.com.myns.svc.cluster.local → NXDOMAIN
api.stripe.com.svc.cluster.local      → NXDOMAIN
api.stripe.com.cluster.local          → NXDOMAIN
api.stripe.com                        → ✅ finally

4 round trips to resolve 1 name. Now double it: glibc requests A and AAAA, often in parallel but still separate queries. 8–10 packets to CoreDNS for every external hostname your app resolves.

What that actually costs

  • ~1–4 ms per lookup becomes ~10–40 ms of added latency on a cold resolve
  • CoreDNS QPS inflates ~5× — people "fix" it by scaling CoreDNS, which fixes nothing
  • Classic symptom: a sidecar/egress-heavy pod with p99 spikes, and kubectl logs on CoreDNS full of NXDOMAIN for *.svc.cluster.local garbage names

Prove it in one command

From inside a pod:

for i in $(seq 20); do dig +noall +stats api.stripe.com | grep "Query time"; done

Then compare with the trailing dot:

dig api.stripe.com.    # the dot = "this is absolute, skip the search list"

Same name. One query instead of four.

Three fixes, in order of preference

1️⃣ Use FQDNs with a trailing dot in your app config for external hosts: https://api.stripe.com./v1. Zero cluster changes. (Some libraries/TLS stacks dislike the dot — test it.)

2️⃣ Override ndots per workload — the targeted fix:

spec:
  dnsConfig:
    options:
      - name: ndots
        value: "1"

Trade-off you must understand: with ndots:1, payments (0 dots) still uses the search list, but payments.myns (1 dot) no longer does. Cross-namespace short names break. Use payments.myns.svc.cluster.local explicitly.

3️⃣ Add NodeLocal DNSCache. Doesn't reduce the query count — it just makes the 4 failures cheap and local instead of a network hop.

The trap

Don't set ndots:1 cluster-wide as a reflex. Service discovery by short name is a load-bearing convention in most clusters, and Helm charts are full of redis-master style hostnames. Fix the chatty egress workloads; leave the rest.

Your exercise

Exec into a running pod and run cat /etc/resolv.conf. Count the dots in the busiest external hostname your service calls. Is it under 5? Then run that hostname through dig twice — once bare, once with a trailing dot — and compare "Query time" and the number of queries. How many wasted packets per request does your service pay today?