DNS in Kubernetes: How Pods Find Each Other by Name

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.

Simple Analogy

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.

Record

A and AAAA

Map a name to an IPv4 address (A) or an IPv6 address (AAAA). The most common lookups by far.

Record

CNAME

An alias. It says one name is really another name, and the resolver must look that second name up.

Record

SRV

Describes where a service lives, including both the host name and the port number.

Record

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.

Simple Analogy

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.

1
Name per Service, stable for its lifetime
Many
Pod IPs behind that one name
0
Numbers apps need to memorise
i
Key Idea

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.

Term 1

Pod

One or more containers running together with a shared network identity and its own IP address.

Term 2

Service

A stable virtual address and name in front of a set of Pods, chosen by matching labels.

Term 3

Namespace

A named room inside a cluster used to separate teams, apps, or environments from each other.

Term 4

ClusterIP

The default Service type. It gives the Service a virtual IP reachable only from inside the cluster.

Term 5

Cluster Domain

The tail of every internal name. By default it is cluster.local, though administrators may change it.

Term 6

EndpointSlice

The live list of Pod addresses currently behind a Service. DNS and traffic routing both depend on it.

Term 7

CoreDNS

The DNS server program that runs in the cluster and answers all the internal name questions.

Term 8

kube-dns Service

The Service in front of the DNS server Pods. For historical reasons it is still called kube-dns.

Simple Analogy

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.

i
Good to Know

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.

Simple Analogy

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
        
FIG 1 — Application asks the kube-dns Service, which spreads questions across CoreDNS Pods

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.

Simple Analogy

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

1

Nameserver

The virtual IP of the kube-dns Service. Every question the application asks goes to this address first.

2

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.

3

Options

Tuning settings, most importantly a number called ndots, explained in Chapter 8.

i
Good to Know

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.

PartExampleMeaning
Service namepaymentsThe name you gave the Service when you created it
NamespaceshopThe room in the cluster where the Service lives
Type markersvcTells DNS this name belongs to a Service
Cluster domaincluster.localThe 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.

Simple Analogy

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.

!
Common Mistake

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.

Simple Analogy

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.

Simple Analogy

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
        
FIG 2 — Why one external lookup may cause several questions to CoreDNS
i
Practical Tip

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.

!
Common Mistake

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.

Simple Analogy

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
        
FIG 3 — Journey of a lookup for an in-cluster Service name
1

Application Asks

The program wants to talk to payments and hands the name to the operating system’s resolver.

2

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.

3

A CoreDNS Pod Receives It

The Service spreads questions across all healthy DNS Pods, so any one of them may answer.

4

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.

5

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.

“DNS tells you where the front door is. Kubernetes networking decides which room you actually walk into.”

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.

Simple Analogy

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.

Plugin

kubernetes

Answers questions about Services and Pods in the cluster domain by using live data from the API.

Plugin

forward

Sends every other question to upstream DNS servers, such as the ones used by the node.

Plugin

cache

Remembers answers for a short time so repeated questions are answered instantly.

Plugin

loop

Detects a forwarding loop, where DNS keeps asking itself, and stops it before it eats resources.

Plugin

health and ready

Expose small checks so Kubernetes knows whether a CoreDNS Pod is alive and ready for traffic.

Plugin

prometheus

Publishes metrics about questions, answers, errors, and speed for monitoring tools to collect.

Plugin

errors and log

Report problems and, if enabled, record every question for debugging.

Plugin

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.

PolicyWhat It DoesWhen to Use
ClusterFirstAsks cluster DNS first; unknown names are forwarded upstreamThe default for nearly every Pod
DefaultInherits the resolver settings from the node the Pod runs onWhen a Pod must ignore cluster names entirely
ClusterFirstWithHostNetSame as ClusterFirst, but for Pods sharing the node’s networkHost-network Pods that still need Service names
NoneIgnores everything and uses only settings you provide manuallySpecial cases needing full control
!
Common Mistake

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.

Simple Analogy

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
        
FIG 4 — A per-node cache answers repeated questions locally

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.

Simple Analogy

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

1

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.

2

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.

3

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.

4

Protect During Maintenance

Use a disruption budget so that upgrades and node drains never remove all DNS Pods at once.

5

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.

Risk 1

Information Leakage

Anyone inside the cluster can ask DNS to list Services and their addresses, which helps an attacker map the environment.

Risk 2

DNS Flooding

A misbehaving or hostile workload can bombard CoreDNS with questions and slow down the whole cluster.

Risk 3

Data Smuggling

Attackers can hide stolen data inside strange-looking external name lookups, a trick called DNS tunnelling.

Risk 4

Config Tampering

Anyone allowed to edit the Corefile ConfigMap can redirect names anywhere they like.

Simple Analogy

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.

!
Common Mistake

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?”.

Rate
Questions per second, split by type
Errors
Server failures and refusals over time
Latency
How long answers take, especially slow tail
What to WatchWhy It MattersWarning Sign
Request volumeShows load and helps plan scalingSudden spikes with no traffic change
Response codesReveals failing or missing namesRising server failures or not-found answers
Response timeSlow DNS makes everything slowHigh slow-tail latency
Cache hit ratioShows how much work the cache savesVery low hit rate on busy clusters
Pod restartsSignals crashes or memory pressureRepeated 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.

Simple Analogy

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.

ANTI-PATTERN-01 Avoid
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.

ANTI-PATTERN-02 Avoid
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.

ANTI-PATTERN-03 Avoid
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
i
Habit to Build

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.

1

Confirm the Service Exists

Check that the Service is in the namespace you expect, and that its name is spelled exactly as used.

2

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.

3

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.

4

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.

5

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.

6

Check Network Rules

Network policies or firewalls may be blocking traffic to DNS on its standard port, over both connection types.

7

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.

!
Common Mistake

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

Q1Is DNS built into every Kubernetes cluster?

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.

Q2Why is the DNS Service still called kube-dns if CoreDNS is used?

For backward compatibility. Many components were already configured to look for that name, so it was kept even after the software behind it changed.

Q3Can Pods in different namespaces talk using names?

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.

Q4Why do some external lookups feel slow inside the cluster?

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.

Q5What is the difference between a normal and a headless Service?

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.

Q6Do I need to restart Pods after changing DNS settings?

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.

Q7Can I change the cluster domain from cluster.local?

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.

Q8How many CoreDNS Pods should I run?

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.

Q9Does DNS load-balance traffic?

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.

Q10Is CoreDNS the only choice?

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.