DNS in Kubernetes: How Pods Find Each Other by Name
A beginner-friendly tour of the invisible phone book inside every Kubernetes cluster: how names become addresses, who answers the questions, and what to check when a lookup goes wrong.
Imagine you move to a huge new city where every house changes its street number every few days. Houses get demolished, rebuilt, and renumbered constantly. Now imagine you have to send a letter to your friend “Payments” who lives somewhere in that city. If you memorised a street number yesterday, your letter probably goes to the wrong place today. What you really need is a helpful post office clerk who always knows the current address of every friend, so you only need to remember a name. Kubernetes has exactly this problem, and DNS is the clerk that solves it.
1What Is DNS, Really?
Before Kubernetes enters the picture, let us understand the plain idea of DNS.
The Phone Book of the Internet
DNS stands for Domain Name System. Computers talk to each other using numbers called IP addresses, such as a long string of digits separated by dots. Humans are terrible at remembering numbers but good at remembering words. DNS is the system that turns a friendly name into the number a computer actually needs. When you type a website name into your browser, a DNS lookup happens first, and only after the number comes back does the real conversation begin.
Think of the contacts app on your phone. You tap the name “Mom”, and the phone dials the number for you. You never see or remember the digits. DNS is the contacts app for computers, and a DNS server is the place where the contact list is stored.
Records: The Entries in the Book
Each entry in the DNS phone book is called a record. Different record types answer different questions. An address record says “this name lives at this IP address”. An alias record says “this name is just another name for that other name”. A service record says “this name offers a service on this port”. You will meet all three of these in a Kubernetes cluster, so it helps to keep them in mind.
A and AAAA
Map a name to an IPv4 address (A) or an IPv6 address (AAAA). The most common lookups by far.
CNAME
An alias. It says one name is really another name, and the resolver must look that second name up.
SRV
Describes where a service lives, including both the host name and the port number.
PTR
The reverse lookup. Given an IP address, it returns the name that belongs to it.
Resolvers and Servers
Two roles appear in every lookup. The resolver is the small helper built into an application or operating system that asks the question. The DNS server is the machine that knows the answer, or knows who to ask next. In this tutorial, the resolver sits inside every container, and the DNS server is a special component that runs inside the cluster.
2Why Kubernetes Needs Its Own DNS
Kubernetes is a place where addresses are temporary, so names must be permanent.
Pods Come and Go
A Pod is the smallest running unit in Kubernetes, usually holding one application container. Every Pod receives its own IP address when it starts. But Pods are disposable. They crash, get replaced during updates, move to other machines when a machine fails, and scale up and down as traffic changes. Each replacement Pod gets a brand-new IP address. If one application had to remember the IP address of another Pod, it would break constantly.
A food-court has a stall called “Noodle House”. The staff behind the counter change every shift, but customers do not care about the staff. They walk to the sign that says Noodle House. The sign is the stable name, and the staff are the short-lived Pods.
Services Give a Stable Front Door
Kubernetes solves part of this with an object called a Service. A Service is a stable virtual address placed in front of a group of Pods. Clients talk to the Service, and Kubernetes quietly forwards their traffic to whichever healthy Pods are currently behind it. The Service address does not change while the Service exists.
That still leaves one small problem. A stable IP address is better than a changing one, but it is still a number. Nobody wants to copy a number into a configuration file and hope it never changes. Kubernetes DNS gives each Service a stable, human-readable name so that applications can simply say “talk to payments” and let the cluster do the rest.
Kubernetes DNS is what makes “service discovery” work. Service discovery simply means finding where something lives without hard-coding its address.
3Core Building Blocks You Must Know
Eight small terms carry almost the entire story of DNS in Kubernetes.
Pod
One or more containers running together with a shared network identity and its own IP address.
Service
A stable virtual address and name in front of a set of Pods, chosen by matching labels.
Namespace
A named room inside a cluster used to separate teams, apps, or environments from each other.
ClusterIP
The default Service type. It gives the Service a virtual IP reachable only from inside the cluster.
Cluster Domain
The tail of every internal name. By default it is cluster.local, though administrators may change it.
EndpointSlice
The live list of Pod addresses currently behind a Service. DNS and traffic routing both depend on it.
CoreDNS
The DNS server program that runs in the cluster and answers all the internal name questions.
kube-dns Service
The Service in front of the DNS server Pods. For historical reasons it is still called kube-dns.
Picture an apartment complex. The complex is the cluster. Each building is a namespace. Each apartment is a Pod. The reception desk of each building is a Service, and the security office that hands out directions is CoreDNS.
The name kube-dns is a leftover from the older DNS component. Modern clusters run CoreDNS, but the Service in front of it keeps the old name so that everything already pointing at it keeps working.
4Meet CoreDNS: The Cluster’s Address Clerk
CoreDNS is a small, fast, plug-in based DNS server, and it is the default in modern Kubernetes.
What CoreDNS Does
CoreDNS runs as a normal application inside the cluster, usually as a Deployment with two or more copies in the system namespace. It has two jobs. First, it answers questions about names that belong to the cluster, such as Services and certain Pods. Second, for every other name, such as a public website, it forwards the question to an upstream DNS server outside the cluster and passes the answer back.
How It Knows About the Cluster
CoreDNS does not keep a hand-written list of names. Instead, it watches the Kubernetes API, which is the central brain of the cluster. Whenever a Service or its endpoints are created, changed, or deleted, CoreDNS hears about it almost immediately and updates what it can answer. That is why a brand-new Service becomes resolvable within moments, without any human editing a DNS file.
A receptionist in a busy office does not print a new staff directory every day. Instead, the receptionist has a live screen linked to the HR system. When somebody joins or leaves, the screen updates and the receptionist answers correctly straight away.
Where It Sits
flowchart LR
A["Application Pod"] -->|"1. Where is payments?"| B["kube-dns Service"]
B --> C["CoreDNS Pod 1"]
B --> D["CoreDNS Pod 2"]
C -->|"2. Watches"| E["Kubernetes API"]
D -->|"2. Watches"| E
C -->|"3. Unknown names"| F["Upstream DNS"]
D -->|"3. Unknown names"| F
Notice that the application never talks to a CoreDNS Pod directly. It talks to the stable kube-dns Service address, which spreads questions across the available CoreDNS Pods. That means DNS itself enjoys the same stable-address benefit as every other Service.
5How a Pod Learns Who to Ask
Every container starts life already knowing where the cluster’s DNS server lives.
The Resolver Configuration File
Inside every Linux container there is a small text file named resolv.conf. It tells the resolver three things: the address of the DNS server to ask, a list of “search domains” to try, and some tuning options. When Kubernetes starts a Pod, the node agent called the kubelet writes this file for the container automatically. The DNS server address it writes is the address of the kube-dns Service.
When a new employee joins a company, the first-day welcome pack already contains the number of the help desk. Nobody needs to search for it. The kubelet is the person who prepares that welcome pack for every new Pod.
The Three Things Written Inside
Nameserver
The virtual IP of the kube-dns Service. Every question the application asks goes to this address first.
Search Domains
A list of suffixes such as the Pod’s namespace, the Service domain, and the cluster domain. These let you type short names.
Options
Tuning settings, most importantly a number called ndots, explained in Chapter 8.
Because the file is written when the Pod starts, changing the cluster’s DNS settings does not rewrite the file in Pods that are already running. Those Pods usually need to be restarted to pick up the change.
6The Anatomy of a Service Name
Every Service gets a predictable, fully qualified name built from four parts.
Reading a Full Name
The full name of a Service is written as the Service name, then the namespace, then the word svc, then the cluster domain, all joined by dots. So a Service called payments in a namespace called shop has the full name payments, shop, svc, cluster, local joined with dots. Reading from left to right, it goes from the most specific thing to the most general thing, just like an address that goes from house number to street to city to country.
| Part | Example | Meaning |
|---|---|---|
| Service name | payments | The name you gave the Service when you created it |
| Namespace | shop | The room in the cluster where the Service lives |
| Type marker | svc | Tells DNS this name belongs to a Service |
| Cluster domain | cluster.local | The default root of every internal name |
Short Names That Still Work
You rarely type the full name. If your application Pod is in the same namespace as the Service, the plain word payments is enough. If the Service is in a different namespace, you add the namespace, for example payments dot shop. The search domains in the resolver file fill in the rest automatically. This is a big convenience, because the same configuration can be copied across environments without changing any names.
Inside your own building, you say “call reception”. To reach a different building, you say “call reception in the north building”. Only when writing to another country do you spell out the complete address. Search domains let Kubernetes do the same politeness shortcuts for names.
Using a short name for a Service in a different namespace. The short name only searches your own namespace first, so the lookup fails or, worse, finds a different Service with the same name locally.
7Records Kubernetes Creates for You
Different objects produce different kinds of answers, and knowing which is which saves hours of confusion.
Normal Service (ClusterIP)
The Service name resolves to one single virtual IP. The client connects to that IP, and Kubernetes spreads the connections across healthy Pods behind the scenes. This is what most applications use.
Headless Service
A Service created without a virtual IP. The name resolves to the individual IP addresses of all the ready Pods behind it, so the client sees every Pod and can choose. Databases and clustered systems love this.
Named Port (SRV) Records
When a Service port has a name, DNS also publishes a service record that says which port number that named port uses. Clients that understand SRV lookups can discover both host and port from a single question.
ExternalName Service
A Service that points outside the cluster. Instead of an IP, DNS returns an alias to an external name, such as a managed database hosted by a cloud provider. Applications keep using a local name while the target can change freely.
Pod Records
Pods can also be reached by a name derived from their IP address with the dots replaced by dashes. This is rarely used directly, because Pod addresses are temporary, but it exists for special situations.
A normal Service is like calling a company’s main phone number and being routed to whoever is free. A headless Service is like getting the direct extensions of every employee. An ExternalName Service is like a contact card saying “for this, call the partner company”.
8Search Domains and the ndots Setting
This is the most misunderstood corner of Kubernetes DNS, and it explains many mysterious slowdowns.
How Short Names Get Expanded
When your application asks for a name, the resolver has to decide whether the name is already complete or needs a suffix added. The ndots setting is the rule it uses. It means: if the name contains fewer dots than this number, try adding the search domains first, and only afterwards try the name exactly as typed. Kubernetes sets ndots to five by default, which is quite high.
Suppose a postal worker gets a letter addressed only to “Ravi”. Because that is so short, the worker first checks the local building, then the neighbourhood, then the city, and only at the very end assumes it might be a famous person. A name with many dots is treated like a fully written address and tried directly.
The Hidden Cost for External Names
A public website name typically has only two or three dots, which is fewer than five. So the resolver treats it as “short” and first tries it with each search domain added. Every one of those attempts is a real question sent to CoreDNS, and each returns “no such name” before the correct final attempt succeeds. A single lookup can quietly become four or five.
flowchart TD
A["App asks for api.example.com"] --> B{"Fewer dots than ndots?"}
B -->|"Yes"| C["Try with namespace suffix"]
C --> D["Try with svc suffix"]
D --> E["Try with cluster suffix"]
E --> F["Try exact name"]
F --> G["Answer returned"]
B -->|"No"| F
Writing a name with a dot at the very end marks it as fully qualified. The resolver then skips all the search domains and asks exactly once. Lowering ndots for a workload that mostly calls external names is another common fix.
Blaming the network for slow external calls when the real cause is the extra failed lookups caused by ndots. Always count how many questions a single name really produces.
9Headless Services and StatefulSet Identities
Some applications need to address individual members, not just “whoever is free”.
Why Individual Names Matter
A database cluster usually has a leader and several followers. The followers must connect to the leader specifically, and every member must know exactly who the others are. Sending traffic to a random Pod would be wrong here. These applications need each member to have a stable, individual name that survives restarts.
How Kubernetes Delivers It
A StatefulSet is a Kubernetes object that runs Pods with stable numbered identities, such as the first, the second, and the third member. When it is paired with a headless Service, each Pod gets its own DNS name made of the Pod name, then the Service name, then the usual namespace and cluster domain. If a Pod is recreated, it returns with the same name, even though its IP address may change, and DNS is updated to the new address.
Think of a school with numbered roll calls. Student number two is always called number two, even if she changes seats every day. Teachers look her up by roll number, not by seat. The name stays stable, and the seat is the changing IP address.
Advantages
- Every member has a predictable, permanent name
- Peers can find each other without any external registry
- Clients can see all ready Pods and pick smartly
- Works naturally with clustered databases and queues
- Recreated Pods keep their identity
Disadvantages / Trade-offs
- No built-in load spreading, so clients must handle it
- Clients may cache stale addresses if they resolve rarely
- More moving parts than a simple Service
- Only ready Pods are listed by default, which can surprise newcomers
10The Life of One DNS Lookup
Let us follow a single question from the moment an application asks it to the moment it gets an answer.
sequenceDiagram
participant App as Application
participant Res as Container Resolver
participant Svc as kube-dns Service
participant CD as CoreDNS
participant API as Kubernetes API
participant Up as Upstream DNS
App->>Res: Connect to payments
Res->>Svc: Ask about payments.shop.svc.cluster.local
Svc->>CD: Forward question to a CoreDNS Pod
CD->>API: Consults its watched list of Services
API-->>CD: Service and endpoints data
CD-->>Res: Answer with the Service address
Res-->>App: Address ready
App->>App: Opens connection
Note over CD,Up: Names outside the cluster go to upstream DNS
Application Asks
The program wants to talk to payments and hands the name to the operating system’s resolver.
Resolver Expands the Name
Using the search domains and ndots rule, it builds the full name and sends the question to the kube-dns Service address.
A CoreDNS Pod Receives It
The Service spreads questions across all healthy DNS Pods, so any one of them may answer.
CoreDNS Checks Its Cluster Knowledge
It already holds an up-to-date copy of the Service and endpoint information it learned by watching the API, so it answers immediately.
The Answer Comes Back
The resolver hands the address to the application, which opens its connection. Kubernetes networking then carries the traffic to a real Pod.
11Inside CoreDNS: The Plugin Chain
CoreDNS is built like a row of small workers, each doing exactly one job.
The Corefile
CoreDNS is configured by a single text file called the Corefile. In Kubernetes, this file usually lives inside a ConfigMap, which is a Kubernetes object that stores configuration. The Corefile lists plugins, and every incoming question passes through them in a fixed order. Each plugin can answer the question, change it, or hand it to the next plugin.
Think of an airport security line. First, someone checks your ticket, then your bag is scanned, then your ID is verified, and finally you board. Each station has one job. CoreDNS plugins work the same way, one small job at a time.
kubernetes
Answers questions about Services and Pods in the cluster domain by using live data from the API.
forward
Sends every other question to upstream DNS servers, such as the ones used by the node.
cache
Remembers answers for a short time so repeated questions are answered instantly.
loop
Detects a forwarding loop, where DNS keeps asking itself, and stops it before it eats resources.
health and ready
Expose small checks so Kubernetes knows whether a CoreDNS Pod is alive and ready for traffic.
prometheus
Publishes metrics about questions, answers, errors, and speed for monitoring tools to collect.
errors and log
Report problems and, if enabled, record every question for debugging.
reload
Lets CoreDNS notice Corefile changes and apply them without a full restart.
Custom Rules Without Chaos
Teams often add extra blocks to the Corefile. A common example is sending all questions for a company-internal domain to the corporate DNS servers, while everything else follows the default path. Because the configuration is a ConfigMap, it can be reviewed, versioned, and rolled back like any other change.
12DNS Policies: Choosing How a Pod Resolves Names
Each Pod can choose its own resolving style, using a setting called dnsPolicy.
| Policy | What It Does | When to Use |
|---|---|---|
| ClusterFirst | Asks cluster DNS first; unknown names are forwarded upstream | The default for nearly every Pod |
| Default | Inherits the resolver settings from the node the Pod runs on | When a Pod must ignore cluster names entirely |
| ClusterFirstWithHostNet | Same as ClusterFirst, but for Pods sharing the node’s network | Host-network Pods that still need Service names |
| None | Ignores everything and uses only settings you provide manually | Special cases needing full control |
The policy called Default is not actually the default. The real default is ClusterFirst. Many people are surprised when a Pod set to Default suddenly cannot find any Service by name.
Fine-Tuning with Custom DNS Settings
Alongside the policy, a Pod can carry extra DNS configuration: additional name servers, extra search domains, or changed options such as ndots. When the policy is set to None, this becomes the only source of settings. This is the correct, supported way to adjust behaviour for a single workload without touching cluster-wide configuration.
ClusterFirst is like asking the office receptionist first and the outside directory only if needed. Default is like ignoring the receptionist and using the phone book at home. None is like writing your own list of numbers by hand.
13Caching and NodeLocal DNSCache
The fastest question is the one that never leaves the machine.
Why Caching Helps
In a busy cluster, thousands of Pods ask for the same handful of names again and again. Answering each one by travelling across the network to a CoreDNS Pod wastes time and adds load. CoreDNS already keeps a short-lived cache, but there is a way to bring the cache even closer to the applications.
The Per-Node Helper
NodeLocal DNSCache is an optional add-on that runs a small DNS caching agent on every node, using a special local address. Pods on that node ask the local agent first. If it already knows the answer, it replies instantly without any network hop. If it does not, it asks the central CoreDNS and remembers the reply. It also talks to CoreDNS over a more reliable connection type, which avoids some rare packet-loss headaches.
flowchart LR
P1["Pod A"] --> L["Local DNS cache on node"]
P2["Pod B"] --> L
L -->|"Cache hit"| P1
L -->|"Cache miss"| C["Central CoreDNS"]
C --> L
Advantages
- Much lower lookup delay for popular names
- Far less traffic to central CoreDNS Pods
- More stable behaviour under heavy load
- Keeps answering cached names even if central DNS briefly struggles
Disadvantages / Trade-offs
- One more component to install, upgrade, and watch
- Stale answers are possible until cache time expires
- A node-level problem affects every Pod on that node
14Scaling and Keeping DNS Available
If DNS stops, almost everything else stops with it, so it deserves careful planning.
Why DNS Is a Critical Dependency
Nearly every application call begins with a name lookup. If DNS becomes slow, every request becomes slow. If DNS disappears, applications cannot even find their own databases. That is why DNS is treated as critical infrastructure, more like electricity than like an ordinary app.
Imagine a city where every taxi driver must call one dispatcher for directions before every trip. If the dispatcher is overloaded, the entire city grinds to a halt, even though every taxi is working perfectly.
Ways to Keep It Healthy
Run Several Copies
Never rely on a single CoreDNS Pod. Keep at least two, and spread them across different machines so one failing node does not take out DNS.
Scale with the Cluster
A common approach is to grow the number of DNS Pods in proportion to the number of nodes or CPU cores, using an autoscaler designed for that purpose.
Set Resource Requests and Limits
Give each DNS Pod enough memory and processor time, and make sure it is scheduled with high priority so it is never squeezed out.
Protect During Maintenance
Use a disruption budget so that upgrades and node drains never remove all DNS Pods at once.
Add Node-Local Caching
Reduce the load reaching central DNS by answering repeat questions on each node.
15Security Considerations
DNS is a quiet doorway, and quiet doorways deserve locks.
Information Leakage
Anyone inside the cluster can ask DNS to list Services and their addresses, which helps an attacker map the environment.
DNS Flooding
A misbehaving or hostile workload can bombard CoreDNS with questions and slow down the whole cluster.
Data Smuggling
Attackers can hide stolen data inside strange-looking external name lookups, a trick called DNS tunnelling.
Config Tampering
Anyone allowed to edit the Corefile ConfigMap can redirect names anywhere they like.
If the building directory is editable by any visitor, someone could change the sign for the bank to point to a fake office. Protecting DNS is about controlling who can edit the directory and who can flood the reception desk.
Practical Protections
Restrict who may change the DNS configuration through role-based access control. Use network policies, which are Kubernetes firewall rules, to allow DNS traffic only where needed and to limit which workloads can reach external resolvers directly. Watch for unusual bursts of failed or very long lookups. Keep CoreDNS updated so security fixes arrive quickly. Finally, remember that ordinary DNS answers are not signed inside the cluster, so sensitive connections should always be protected with encryption and identity checks at the application layer.
Assuming that a name resolving correctly proves you are talking to the right service. DNS only tells you where to go, not who is there. Always verify identity with encrypted connections.
16Monitoring, Logging, and Metrics
You cannot fix what you cannot see, and DNS problems are famously invisible.
The Signals Worth Watching
CoreDNS publishes metrics that a monitoring system can collect. The most valuable ones tell a simple story about traffic, errors, and speed. Together they answer the questions “how many questions per second?”, “how many are failing?”, and “how long do answers take?”.
| What to Watch | Why It Matters | Warning Sign |
|---|---|---|
| Request volume | Shows load and helps plan scaling | Sudden spikes with no traffic change |
| Response codes | Reveals failing or missing names | Rising server failures or not-found answers |
| Response time | Slow DNS makes everything slow | High slow-tail latency |
| Cache hit ratio | Shows how much work the cache saves | Very low hit rate on busy clusters |
| Pod restarts | Signals crashes or memory pressure | Repeated restarts of DNS Pods |
Logging with Care
CoreDNS can log every single question, which is priceless when debugging a stubborn problem. But on a busy cluster, that produces a mountain of logs and adds load. Turn it on temporarily, investigate, and turn it off again. For everyday visibility, rely on metrics and on error logs.
Metrics are the dashboard lights in a car: speed, fuel, temperature. Detailed logs are like connecting a diagnostic computer to the engine. You do not keep the computer plugged in during every trip, only when something feels wrong.
17Design Patterns and Anti-Patterns
Good habits make DNS boring, and boring is exactly what you want.
Pattern: One Name per Dependency
Applications refer to each dependency by a single stable Service name, supplied through configuration. Moving from a test database to a production one is then a configuration change, not a code change.
Pattern: ExternalName as a Migration Bridge
While moving a service out of the cluster, or into it, use a local alias name. Applications never notice when the real target changes.
Pattern: Headless Service for Peer Discovery
Clustered software uses a headless Service so each member can discover all the others by asking a single name.
Pattern: Local Cache plus Redundant Central DNS
A per-node cache handles the bulk of repeated questions, while several central DNS Pods handle the rest.
Problem
Applications are configured with Pod IP addresses, or even Service IP addresses, instead of names.
Why It’s Harmful
Pod addresses change constantly, and even Service addresses can change if the Service is deleted and recreated. Hard-coded numbers cause outages that are very hard to trace.
Correct Approach
Always use Service names, and let DNS translate them at connection time.
Problem
Long-running applications resolve a name once at startup and reuse the answer forever.
Why It’s Harmful
When the backing Pods change, the application keeps talking to addresses that no longer exist, especially with headless Services.
Correct Approach
Re-resolve names periodically, respect the time-to-live on answers, and configure connection pools to refresh.
Problem
Running a single CoreDNS Pod, or many DNS Pods all on the same node.
Why It’s Harmful
One failure removes name resolution for the entire cluster, and everything cascades.
Correct Approach
Run multiple replicas spread across nodes, with scaling and disruption protection in place.
18Best Practices and Common Mistakes
A short checklist that prevents most DNS trouble before it starts.
Best Practices
- Use short names inside a namespace and namespace-qualified names across namespaces
- Add a trailing dot to external names in performance-sensitive paths
- Tune ndots for workloads that mostly call outside services
- Run at least two CoreDNS Pods on separate nodes
- Monitor rate, errors, and latency continuously
- Consider node-local caching for large or busy clusters
Common Mistakes
- Confusing DNS failures with network failures
- Forgetting that existing Pods keep old resolver settings
- Leaving detailed query logging on permanently
- Copying the same Service name in many namespaces without care
- Editing the Corefile without a tested rollback plan
- Ignoring DNS in capacity planning
Whenever something “cannot connect”, ask this first: does the name resolve? Many long debugging sessions end with a simple answer that was one DNS check away.
19Troubleshooting: A Calm Step-by-Step Approach
When a name will not resolve, walk through the same short path every time.
Confirm the Service Exists
Check that the Service is in the namespace you expect, and that its name is spelled exactly as used.
Check It Has Ready Endpoints
A Service with no ready Pods behind it may resolve but lead nowhere, and a headless one may return nothing at all.
Test from Inside a Pod
Use a small debugging Pod in the same namespace and look up the name from there. Testing from your laptop proves nothing about in-cluster DNS.
Inspect the Resolver File
Look at the nameserver and search domains inside the failing Pod. A wrong policy or manual override is often the culprit.
Verify CoreDNS Health
Confirm the DNS Pods are running, ready, and not restarting. Read their error logs for clues such as loops or unreachable upstream servers.
Check Network Rules
Network policies or firewalls may be blocking traffic to DNS on its standard port, over both connection types.
Turn On Temporary Query Logging
If the cause is still unclear, enable detailed logging briefly, reproduce the problem, read what was asked and answered, then switch it off.
Skipping straight to restarting things. Restarts may hide the symptom for a while, but without knowing the cause, the same failure usually returns at the worst moment.
20Real-World Examples
Here is how DNS quietly powers everyday cluster designs.
Online Shop with Many Small Services
A shopping site splits into catalogue, cart, payments, and shipping services. The cart simply calls the payments Service by name. During a sale, payments scales from three Pods to thirty, and the cart never changes a single setting because the name stays the same.
Clustered Database
A three-member database uses a StatefulSet and headless Service. Each member finds the others by their individual names. When one member is rebuilt after a node failure, it returns under the same name and rejoins the group.
Multi-Team Platform
A large company gives each team its own namespace. Teams call each other using namespace-qualified names, which makes ownership clear and prevents accidental name clashes.
Gradual Move to a Managed Cloud Database
An application currently talks to a database running inside the cluster. The team creates an alias-style Service that points to the managed database instead. Applications keep the same name, and the switch is invisible to them.
High-Traffic Streaming Platform
A platform with thousands of nodes uses node-local caching and automatic scaling of DNS Pods. Busy names are answered on each node, and central DNS handles only the leftovers, which keeps latency low during huge events.
21Frequently Asked Questions
Almost always. It is delivered as a standard add-on, and practically every mainstream installation includes it by default. Without it, Service names would not resolve.
For backward compatibility. Many components were already configured to look for that name, so it was kept even after the software behind it changed.
Yes. Add the namespace to the Service name, or use the full name. Namespaces separate things logically, but they do not block DNS lookups by themselves.
Most often because of the ndots setting and search domains, which cause several failed attempts before the right one. A trailing dot or a lower ndots value usually helps.
A normal Service gives one virtual address and spreads traffic for you. A headless Service returns the individual Pod addresses and leaves the choice to the client.
Often yes. The resolver file is created when a Pod starts, so existing Pods keep their old copy. Changes to CoreDNS answers themselves apply without restarting application Pods.
It can be changed when the cluster is created or configured, but it is unusual and needs consistent settings in several places. Most teams keep the default.
At least two, spread across different nodes. Larger clusters should scale the number in proportion to their size and watch the load and latency metrics.
Not in the way a load balancer does. For normal Services, the cluster networking layer spreads the connections. For headless Services, DNS may return several addresses and clients pick one.
It is the standard and by far the most common. Other DNS implementations can be used if they follow the same rules for Kubernetes names, but that is rarely necessary.
22Summary and Key Takeaways
Kubernetes is a world where Pods are born, die, and move constantly, so no address can be trusted for long. DNS gives every Service a permanent, readable name, and CoreDNS keeps that phone book perfectly up to date by watching the cluster itself. Each container is told where to ask through an automatically prepared resolver file, search domains let you type short names, and different Service types produce different kinds of answers. With a little care around ndots, caching, redundancy, security, and monitoring, DNS becomes the quiet foundation that lets every other part of the cluster find its friends.
Key Takeaways
- Names beat numbers — Pod and even Service addresses can change, so applications should always use names.
- CoreDNS is the clerk — it watches the Kubernetes API and answers every in-cluster question, forwarding the rest upstream.
- Learn the name pattern — service, namespace, svc, and cluster domain, with short forms made possible by search domains.
- Choose the right Service type — normal for simplicity, headless for peer discovery, ExternalName for aliasing outside targets.
- Mind ndots — the default of five can multiply lookups for external names; trailing dots and tuning help.
- Protect DNS like a critical utility — several replicas, autoscaling, node-local caching, and disruption protection.
- Observe and secure it — watch rate, errors, and latency, restrict who edits configuration, and never treat a resolved name as proof of identity.