Skip to content

Lesson 15 of 19 · 15m

CoreDNS, ndots, and the Five-Query Tax

kubelet writes every pod's resolv.conf with search domains and ndots:5, so short hostnames fire a string of NXDOMAINs before the real lookup — and UDP conntrack makes it worse.

Resolve api.payments.internal from inside a pod and Kubernetes doesn't ask CoreDNS once. kubelet wrote that pod's /etc/resolv.conf with options ndots:5 and a search list of <ns>.svc.cluster.local, svc.cluster.local, cluster.local, plus whatever search domains the node's own resolv.conf carried. ndots:5 means: if the name has fewer than five dots, try every search domain first. api.payments.internal has two dots. So the resolver asks for api.payments.internal.<ns>.svc.cluster.local, then .svc.cluster.local, then .cluster.local, then the node's domains — each an NXDOMAIN in sequence — and only then asks for the name you meant. Four or five lookups for one address. On an app making thousands of resolutions a minute, that is real load on CoreDNS and on conntrack — and the NXDOMAINs are the slowest queries in the system, each one waiting on a round trip before the next candidate is tried. This is the "DNS latency" half the Kubernetes community has been chasing since 2019; it is not a capacity problem, it is a search-list problem.

Where names resolve

kube-dns is a Service — kubectl get svc kube-dns -n kube-system — backed by CoreDNS pods, usually two replicas behind a ClusterIP, and that ClusterIP is the nameserver kubelet writes into every pod's resolv.conf. CoreDNS runs the kubernetes plugin: it answers service.namespace.svc.cluster.local from API-server data, caches, and forwards everything else to upstream resolvers (forward . /etc/resolv.conf, i.e. the node's resolver). Its Corefile supports stubDomains and rewrite rules too, so clusters can graft corporate zones or split-horizon answers onto cluster DNS without a second resolver. CoreDNS pods are regular pods — if both replicas land on one node, a node failure is a DNS outage. Spread them with topologySpreadConstraints or run NodeLocal DNSCache.

Setting clusterIP: None makes a Service headless: DNS answers with the member pod IPs directly instead of a VIP. That is the mechanism StatefulSets lean on for stable pod identity — pod-0.svc.ns.svc.cluster.local resolves to that pod, not a load-balanced front.

A pod overrides resolution with dnsPolicy and dnsConfig. ClusterFirst is the default and gives the search-domain behavior above; ClusterFirstWithHostNet is its hostNetwork: true variant (otherwise hostNetwork pods inherit the node's resolv.conf verbatim and can't resolve cluster names); None plus a custom dnsConfig lets you set ndots, timeout, and attempts yourself.

The UDP trap under it

DNS rides UDP/53, and every UDP flow through kube-proxy's DNAT occupies a conntrack entry until timeout. glibc's resolver fires the A and AAAA queries in parallel from the same source port — a documented race where conntrack collapses both into one mapping and one reply is dropped. The observable symptom is intermittent five-second stalls. The fix is a resolv.conf option, not a patch: options single-request-reopen sends each query on a fresh socket. Note the caveat — musl libc (Alpine) ignores that option entirely, which is why the same app behaves differently on an Alpine image.

What actually works

  • A trailing dot dodges the tax entirely: api.payments.internal. is absolute, no search list is tried. Cheap fix, ugly to maintain at scale.
  • dnsConfig can override the resolver knobs pod-by-pod:
spec:
  dnsConfig:
    options:
      - { name: ndots, value: "1" }
      - { name: single-request-reopen }

That cuts the search storm for pods that mostly resolve external names, and re-sockets the A/AAAA pair on glibc.

  • NodeLocal DNSCache — a DaemonSet shipped with Kubernetes itself — puts a caching CoreDNS on every node and points pods' resolv.conf at 169.254.20.10. Local stub resolution, TCP upstream to the cluster kube-dns service, which also sidesteps the UDP conntrack race. It is the standard answer at scale.
  • Watch coredns_dns_requests_total and the NXDOMAIN share in metrics before scaling CoreDNS replicas. Most "DNS is slow" reports are the ndots storm, not capacity — the fix is reducing pointless queries, not adding replicas.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.

What is Platform as a Service? The Sweet Spot Between "Too Easy" and "Too Much Work"

Platform as a Service sits between raw servers and fully managed software. You push code, the platform runs it. No Nginx config, no OS patches, no 3 AM server alerts. Here is what PaaS actually gives you, what it costs you in control, and how to decide if it is the right layer for your application.

Article

The World now is Serverless and Container based

A new report from Datadog reveals that serverless computing could be entering the mainstream. This has already been the case in my world for the past few years. Results show that more than half of all organizations are using serverless on one of the three major public cloud providers: Amazon,

Article

PostgreSQL 19 Is Out. REPACK Kept My Writes Running. The Docker Upgrade Will Stop Your App.

PostgreSQL 19 shipped on November 19 with REPACK (CONCURRENTLY), which removes table bloat without blocking writes. I measured it against VACUUM FULL, ran the upgrade from 18, and checked what breaks for self-hosters: Docker tags that refuse to start, a config setting that stops the server, and...

Article

Self-Hosting Prometheus and Grafana: Infrastructure Monitoring That Actually Works

Build a production-grade monitoring stack with Prometheus and Grafana from scratch. Covers architecture, Docker Compose deployment, Node Exporter, alerting with Alertmanager, PromQL from basics to advanced, pre-built dashboards, and everything SudoSecurity uses to monitor its own infrastructure.

Article