Zero Labs
Industry News / AI

How Kubernetes DNS Works (and How to Debug “Name Resolution Failed” Errors)

Source · Towards AI By Swapnil Ahire

From the publisher’s feed, collected in the ZeroLabs newsroom.

Every Pod in your cluster is quietly asking a built-in phonebook for directions, thousands of times a day. Here’s what happens when that phonebook stops answering.Cross-namespace communication breaking with “Name Resolution Failed”? Here’s how Kubernetes DNS actually works under the hood with CoreDNS, what that long service.namespace.svc.cluster.local name really means, and how to debug it with nslookup in a real debug Pod.Somewhere in your cluster right now, a Pod is trying to talk to another Pod using a name like my-service.my-namespace.svc.cluster.local, and if you've never had a reason to look closely at that string, it probably looks like gibberish — a domain name that got run over by a URL. It isn't gibberish. It's a very deliberately structured address, and understanding it is the difference between guessing randomly at a fix and actually knowing where to look when you hit the error almost everyone eventually hits: Name Resolution Failed.This one tends to show up at an inconvenient time — usually right after you’ve split an application across multiple namespaces, or when a service that worked fine yesterday suddenly can’t find its database today. And because DNS failures often look identical to network failures, connection failures, or plain misconfiguration, people frequently spend far longer debugging the wrong layer entirely.Let’s fix that, starting with what’s actually resolving these names in the first place.DNS in Kubernetes isn’t a side feature. It’s the reason a Service’s stable address, from earlier in this series, is actually usable by name instead of by memorized IP.Why Kubernetes Needs Its Own DNS System at AllIf you’ve followed the Services article in this series, you already know that Services give Pods a stable address that doesn’t change even as the actual Pods behind it come and go. But a stable IP address alone isn’t very human-friendly, and more importantly, it’s not very automation-friendly either — hardcoding IP addresses into application configuration defeats a huge amount of what makes Kubernetes flexible in the first place.What you actually want is to reference things by name — my-service, not 10.96.142.87 — and have that name reliably resolve to the correct current address, automatically, no matter how many times Pods behind that Service get recreated. That's exactly the job of Kubernetes's internal DNS system.Key takeaway: Kubernetes DNS exists so you can reference Services and Pods by stable, human-readable names instead of memorizing or hardcoding IP addresses that can change.Meet CoreDNS: The Cluster’s PhonebookCoreDNS is the DNS server that runs inside almost every modern Kubernetes cluster, typically as a Deployment living in the kube-system namespace, made up of a small number of Pods quietly answering DNS queries from every other Pod in the cluster, constantly, in the background.Every time a Pod tries to reach something by name — whether that’s another Service, or an external domain like api.github.com — that request usually gets routed to CoreDNS first, which either answers directly (for internal cluster names) or forwards the query upstream (for external internet domains), the same way your home router forwards DNS queries to your ISP for anything it doesn't know locally.You can actually see this running in your own cluster right now:kubectl get pods -n kube-system -l k8s-app=kube-dnsIf that comes back empty or shows Pods that aren’t Running, you've already found a very likely root cause for cluster-wide name resolution problems — which is worth checking early, the same way checking for a running Ingress controller was the first move in the last article.Key takeaway: CoreDNS is real, running software — just like the Ingress controllers from the last article — and checking that it’s actually healthy should be an early step, not a last resort, when names aren’t resolving.Decoding That Long, Ugly Domain NameNow the part that actually looks intimidating the first time you see it: my-service.my-namespace.svc.cluster.local. Once broken into its pieces, it's genuinely straightforward — it's just a very literal, hierarchical address.Reading it left to right: “the Service named my-service, inside the namespace my-namespace, which is a Service-type object, within this cluster's internal domain." cluster.local is the default root domain for cluster-internal DNS (it's configurable, but most clusters leave it as-is), and svc distinguishes Service records from other DNS record types Kubernetes also manages internally, like Pod-specific records.Here’s the part that actually resolves most cross-namespace confusion: you don’t need the full name if you’re calling a Service from within the same namespace. Kubernetes DNS supports shortened forms depending on where the request is coming from:This table is really the entire cross-namespace lesson in one place. A huge share of “it worked before I split things into namespaces” confusion comes down to code that used the short form my-service, which resolved fine when everything lived in one namespace, and silently broke the moment the calling Pod and the target Service ended up in different namespaces — because the short form only works within the same namespace by default.my-service isn't a broken shortcut. It's namespace-relative by design — which is exactly why it stops working the moment your architecture crosses a namespace boundary.Key takeaway: Cross-namespace DNS failures are very often not a DNS problem at all — they’re leftover short-form service names that assumed a same-namespace setup that no longer exists.Debugging with a Real Debug PodWhen something genuinely isn’t resolving, guessing is slower than testing directly, and Kubernetes makes this easy with a temporary, disposable debug Pod — no need to modify your actual application or add debugging tools to a production image.kubectl run dns-debug --image=busybox:1.28 --rm -it --restart=Never -- shThis drops you into an interactive shell inside a brand-new, temporary Pod, and --rm means it cleans itself up automatically the moment you exit — nothing left behind to clutter your cluster later. From inside that shell, you can directly test DNS resolution:nslookup my-servicenslookup my-service.my-namespacenslookup my-service.my-namespace.svc.cluster.localRunning all three, in order, is a genuinely useful diagnostic habit. If the fully-qualified version resolves but the short form doesn’t, you’ve just confirmed a namespace mismatch, not a broken DNS system. If none of them resolve, the problem is more fundamental — possibly a CoreDNS health issue, a network policy blocking DNS traffic, or the Service itself not existing where you think it does.You can also directly check what CoreDNS itself considers healthy by querying its own status, and confirm basic outbound resolution is functioning at all:nslookup kubernetes.defaultnslookup google.comIf kubernetes.default (a Service that should always exist in any working cluster) fails to resolve, that's a strong signal the problem sits with CoreDNS itself, not with your specific application's Service. If external domains like google.com fail but internal names work fine, that points toward CoreDNS's upstream forwarding configuration instead.Key takeaway: A disposable debug Pod with nslookup lets you isolate exactly which layer is failing — namespace scoping, CoreDNS health, or upstream forwarding — instead of guessing based on symptoms in your actual application.A Practical Debugging FlowchartWhen It’s Not Actually DNSIt’s worth being direct about this, because DNS gets blamed for a lot of problems it didn’t cause. If nslookup successfully resolves a name to an IP address, DNS has done its job — anything that fails after that (a connection timeout, a refused connection, an authentication error) is happening at a different layer entirely: networking, firewall/NetworkPolicy rules, or the application itself.A quick way to separate “DNS problem” from “everything else” is testing actual connectivity once resolution succeeds:wget -qO- http://my-service.my-namespace.svc.cluster.localIf nslookup resolves the name correctly but this connection attempt hangs or fails, you've successfully ruled DNS out — the name was found, but something else is blocking the actual traffic. That's a meaningfully different problem with a completely different set of fixes, and confusing the two wastes real debugging time.Key takeaway: Successful name resolution and successful connectivity are two separate things. Test them separately, because a fix for one won’t touch the other.Why Namespaces Complicate This More Than People ExpectNamespaces are genuinely useful — they let teams share a cluster while keeping their resources logically separated, they support cleaner RBAC boundaries, and they make multi-team or multi-environment clusters far more manageable. But that same separation is exactly what breaks short-form DNS names the moment an architecture grows past a single namespace.This is a common turning point for teams: an application starts in one namespace, everything uses short Service names, it all works fine — and then the team splits things up (frontend namespace, backend namespace, database namespace, or per-environment namespaces) for better organization, and suddenly a handful of previously-working service calls start failing with exactly the kind of DNS confusion this article opened with. The fix is almost always the same: update those calls to use the namespace-qualified form, or at minimum, understand clearly which namespace each caller is actually running in.Key takeaway: Growing from a single namespace into multiple namespaces is a very common trigger for DNS-related outages — not because DNS broke, but because namespace-relative shortcuts stopped applying.The Debugging Instinct Worth KeepingThe next time something fails with a vague name-resolution-flavored error, the useful first move isn’t re-reading application code line by line. It’s a short, repeatable sequence: confirm CoreDNS is actually healthy, spin up a disposable debug Pod, run nslookup against the short name and the fully-qualified name separately, and note exactly where resolution starts succeeding or failing. That one sequence turns a vague, anxiety-inducing error message into a specific, narrow question with a specific, narrow answer.DNS in Kubernetes isn’t mysterious once you’ve actually looked at it running — it’s a small, dedicated service doing an enormous number of quiet lookups every single day, following clear and fairly simple naming rules. The frustration almost always comes from nobody explaining those rules clearly the first time you needed them.What’s the strangest DNS-related bug you’ve run into in a Kubernetes cluster — and how long did it take before you realized it wasn’t actually a networking problem?How Kubernetes DNS Works (and How to Debug “Name Resolution Failed” Errors) was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.