Skip to content

Could not resolve host: finding DNS faults in a Kubernetes Pod

Kubernetestested on RKE2 v1.37.2

"Could not resolve host" is DNS, "Could not connect" or "Connection timed out" is the connection. Every Pod asks the cluster DNS via /etc/resolv.conf and, with ndots:5, tries all search domains first. Read the message first, then pick the tool.

Symptom

kubectl -n tag08 exec client -- curl -sS -m 5 api
curl: (6) Could not resolve host: api (Domain name not found)
command terminated with exit code 6

The Service api lives in the namespace tag08-andere, the Pod client in tag08. CoreDNS answers – but with "doesn't exist".

Diagnosis

The Pod's DNS configuration shows the nameserver, the search list and ndots.

kubectl -n tag08 exec client -- cat /etc/resolv.conf
search tag08.svc.cluster.local svc.cluster.local cluster.local localdomain
nameserver 10.43.0.10
options ndots:5

Causes

Domain name not foundThe namespace is missing from the name

The short name api first becomes api.tag08.svc.cluster.local – in the Pod's own namespace. But the Service lives in tag08-andere. The remaining search domains don't help, and localdomain comes from the node.

Resolving timed outDefault-deny blocks DNS

DNS is just traffic too – UDP/TCP 53 to the CoreDNS Pods in kube-system. If no NetworkPolicy allows it, Canal silently drops the queries. The name times out, the IP works.

kubectl -n tag08 exec client -- curl -sS -m 5 api.tag08-andere
curl: (28) Resolving timed out after 5000 milliseconds
command terminated with exit code 28

dnsPolicy: DefaultThe Pod inherits the node's resolver

dnsPolicy Default doesn't mean "the default" but: inherit the node's resolv.conf. Those resolvers don't know cluster.local. The actual default is ClusterFirst.

kubectl -n tag08-andere exec altlast -- grep -v '^#' /etc/resolv.conf
search localdomain
nameserver 172.16.0.15
nameserver 8.8.8.8
nameserver 1.1.1.1

NXDOMAIN from digdig without +search misleads you

nslookup uses the search list like the application does, dig doesn't: it asks for the name literally and gets NXDOMAIN. Only with +search or the fully qualified name does it behave like curl.

kubectl -n tag08 exec client -- dig api.tag08-andere +noall +comments | grep status
kubectl -n tag08 exec client -- dig +search +short api.tag08-andere
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 56523
10.43.131.137

Fix

Across namespace boundaries, use at least <service>.<namespace>. With default-deny, add an egress rule to kube-dns on 53/UDP and 53/TCP; dnsPolicy is immutable, so the Pod has to be recreated with ClusterFirst.
kubectl -n tag08 exec client -- curl -sS -m 5 api.tag08-andere | head -1
Hostname: api-c78ffd49-rwzpk

Don't: Suspecting CoreDNS before you've checked the name. With the log plugin you can see the query arrive and CoreDNS answer correctly with NXDOMAIN.

▶
Break it yourself and find it – free
Debugging Kubernetes, day 8: DNS faults, ndots, CoreDNS logs and NetworkPolicies that block too much or nothing, with a drill to reproduce each one.
Go to day 8 →

FAQ

What does ndots:5 do?

Names with fewer than five dots go through the search list first. An external name like example.com costs several wasted queries that way.

A timeout instead of NXDOMAIN – what does that mean?

No answer comes back at all. That points to a NetworkPolicy or dead CoreDNS Pods.

What is the DNS Service called in RKE2?

Not kube-dns but rke2-coredns-rke2-coredns in kube-system. The label k8s-app=kube-dns has stayed.

Related error patterns

More