ML
Kubernetes

Kubernetes 5-Second DNS Latency: Why ndots:5 and Linux conntrack Race Conditions Stalled UDP Lookups

Under high concurrency, Kubernetes pods using default resolv.conf settings experience periodic 5-second request timeouts. The culprit is a race condition between parallel A and AAAA DNS queries in the Linux netfilter connection tracking table, exacerbated by ndots:5 search domain cascades.

November 29, 202611 min readKubernetesNetworkingLinuxDNSPerformance

In high-throughput microservices deployed on Kubernetes, few intermittent anomalies are as notorious as the sudden 5-second HTTP request spike. An API gateway or payment orchestrator processing hundreds of requests per second suddenly records outbound calls taking exactly 5.002 to 5.008 seconds. Application metrics show zero garbage collection pauses, external third-party endpoints respond in 15 milliseconds, and CPU throttling is absent.

The root cause lies in the intersection of glibc DNS resolver defaults, Kubernetes pod DNS search path configurations, and a longstanding race condition inside the Linux kernel netfilter connection tracking table (nf_conntrack).

1. The ndots:5 Search Domain Cascade

By default, the Kubernetes kubelet populates every pod container with an /etc/resolv.conf file structured like this:

nameserver 10.96.0.10
search production.svc.cluster.local svc.cluster.local cluster.local
options ndots:5

The parameter ndots:5 dictates that if a hostname contains fewer than 5 dots (periods), the DNS resolver must first try appending the local search domains before attempting a query against the absolute root domain.

Consider an application pod making an HTTPS call to an external payment provider, api.stripe.com:

  • The domain api.stripe.com contains exactly 2 dots. Because 2 is less than 5, glibc treats it as an internal cluster name first.
  • Query 1: api.stripe.com.production.svc.cluster.local (returns NXDOMAIN)
  • Query 2: api.stripe.com.svc.cluster.local (returns NXDOMAIN)
  • Query 3: api.stripe.com.cluster.local (returns NXDOMAIN)
  • Query 4: api.stripe.com. (finally succeeds)

Because modern HTTP libraries resolve both IPv4 (A records) and IPv6 (AAAA records) addresses simultaneously, a single outbound call triggers up to 8 separate UDP DNS queries to CoreDNS.

2. The Linux Conntrack Race Condition

The Linux kernel tracks network flows using nf_conntrack. When a pod sends a UDP packet to CoreDNS (ClusterIP 10.96.0.10:53), iptables performs Source Network Address Translation (SNAT) and Destination Network Address Translation (DNAT) to route the packet to an active CoreDNS pod endpoint.

When glibc makes parallel A and AAAA DNS queries from the same UDP socket, both packets are transmitted at virtually the exact same microsecond:

conntrack race sequence:
1. Packet A (IPv4 query)  -> enters netfilter (tuple: src=pod_ip:52134, dst=coredns:53)
2. Packet B (IPv6 query)  -> enters netfilter (tuple: src=pod_ip:52134, dst=coredns:53)
3. Both packets pass NF_IP_PRE_ROUTING hook simultaneously.
4. Neither packet finds an existing conntrack entry for this UDP 5-tuple.
5. Packet A creates unconfirmed conntrack entry and applies NAT.
6. Packet B creates identical unconfirmed conntrack entry and applies NAT.
7. Packet A reaches confirmation stage (nf_conntrack_confirm) and successfully inserts into hash table.
8. Packet B reaches confirmation stage. The tuple already exists in the table!
9. Linux kernel calls nf_ct_drop, dropping Packet B silently on the floor.

Because UDP is a connectionless, best-effort transport protocol, the kernel does not notify the sending application that the packet was discarded. The glibc resolver simply waits for a DNS reply that will never arrive.

3. The 5-Second UDP Retransmission Timeout

Why exactly 5 seconds? In standard glibc implementations (used in Debian, Ubuntu, and Red Hat container base images), the default resolver timeout parameter (timeout:5) is hardcoded to 5 seconds. The resolver sends the UDP query, blocks for 5000 milliseconds waiting for a response, times out, and retransmits the query.

The retransmitted packet enters netfilter, finds the existing confirmed conntrack table entry created by the earlier successful query, traverses NAT cleanly, reaches CoreDNS, and returns in under 1 millisecond. From the application perspective, the operation succeeded, but took exactly 5.005 seconds.

4. Production Solutions

A. Deploy NodeLocal DNSCache

The most resilient architectural fix in Kubernetes clusters is enabling NodeLocal DNSCache. NodeLocal DNSCache runs a DNS caching agent as a DaemonSet on every cluster node, listening on a link-local IP (typically 169.254.20.10):

// Pod queries local loopback IP over UDP:
Pod -> NodeLocal DNSCache (169.254.20.10:53, no conntrack DNAT required)
       +--> If cached: responds in sub-millisecond
       +--> If cache miss: queries CoreDNS over persistent TCP connection

Because communication to the local node bypasses iptables DNAT, and cache misses query CoreDNS over TCP, connection tracking table races on port 53 are completely bypassed.

B. Configure single-request-reopen in Pod DNS Config

If NodeLocal DNSCache is not yet deployed, configure pod-level resolver options to prevent simultaneous A and AAAA socket queries:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: payment-orchestrator
spec:
  template:
    spec:
      dnsConfig:
        options:
          - name: single-request-reopen
          - name: ndots
            value: "2"

The single-request-reopen option forces glibc to close the existing network socket and open a fresh socket with a distinct source port before sending the second query, preventing 5-tuple insertion collisions in conntrack.

C. Reduce ndots or Use Fully Qualified Domain Names (FQDN)

For microservices with heavy outbound third-party traffic, reducing ndots from 5 to 2 eliminates up to 6 wasted NXDOMAIN queries per request. Alternatively, append a trailing dot to external hostnames in your configuration files:

# Trailing dot marks FQDN, skipping the search list entirely:
PAYMENT_GATEWAY_URL="https://api.stripe.com./v1/charges"

Summary

The infamous 5-second Kubernetes DNS delay is the direct result of a kernel conntrack insertion conflict triggered by concurrent UDP queries from glibc, amplified tenfold by the ndots:5 search domain list. Deploying NodeLocal DNSCache, applying single-request-reopen, and tuning ndots eliminates UDP packet drops, restores predictable sub-millisecond DNS lookups, and shields production services from intermittent latency spikes.

SharePostLinkedIn

Reader Discussion

7 replies// weighed in

TopNewestAuthor
Add to the thread
Disagree, agree harder, or share your own experience…
Email instead →markdown okbe kind
  1. Highlighted by author
    Anders Lindqvist· Staff SREStory

    the preStop sleep trick. THE preStop sleep trick. we spent 3 days debugging mystery 5xx during deploys and the answer was a 10-second sleep. there should be a billboard.

    Nov 30, 2026·1 day later
  2. Priscilla Owens· Backend LeadPushback

    small pushback — "never set CPU limits" is too strong imo. on cgroups v2 with steady traffic profiles, soft caps prevent one noisy neighbour from starving the whole node. it's a per-workload call. great post otherwise.

    Dec 06, 2026·1 week later·edited
  3. Jiwoo Park· Junior EngineerKind words

    the "control loop, not deploy tool" framing finally made k8s click for me. been fighting with it for 4 months. wish onboarding docs led with this paragraph instead of YAML.

    Dec 01, 2026·2 days later
  4. Vasili Kurov· Platform EngineerFrom experience

    HPA on CPU only is the silent killer. moved ours to requests-per-pod via prometheus-adapter and our scaling went from "vaguely correct" to actually correlated with load. 2 hours of work, immediate ROI.

    Dec 03, 2026·4 days later
  5. Tiến Hồ🇻🇳 Hà Nội· DevOps EngineerAgrees

    PDB = thứ 90% team mình bỏ qua đến khi GKE node upgrade làm 3 pod down một lúc. minAvailable: 2 cộng với replicas: 3 là default mình deploy bây giờ, không cần suy nghĩ.

    Dec 02, 2026·3 days later
  6. Léa Dubois· SREAsks

    any chance you'd publish these as a PDF collection? would love to print and read offline on flights. screen-fatigue is real.

    Dec 05, 2026·6 days later
  7. Ahmed Rahman· Full StackKind words

    concise + opinionated = my favourite kind of engineering post. so many blogs hedge every claim into mush. give me the spicy take with the receipts. more please.

    Nov 30, 2026·1 day later

Worked on something similar? Email ducminhldm@gmail.com — I read every one. The good ones become future posts.

Comments seeded · live discussion via email