0
0
Kubernetesdevops~10 mins

DNS in Kubernetes (CoreDNS) - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - DNS in Kubernetes (CoreDNS)
Pod sends DNS query
CoreDNS receives query
CoreDNS checks local cache
Return cached IP
No
CoreDNS queries Kubernetes API
CoreDNS resolves service/pod name
CoreDNS returns IP to Pod
Pod connects to resolved IP
This flow shows how a Pod's DNS query is handled by CoreDNS in Kubernetes, resolving service or pod names to IP addresses.
Execution Sample
Kubernetes
kubectl run busybox --image=busybox --restart=Never -- sleep 3600
kubectl exec busybox -- nslookup kubernetes.default
kubectl get svc kubernetes -o jsonpath='{.spec.clusterIP}'
This sequence runs a busybox pod, performs a DNS lookup for the Kubernetes service, and retrieves the service IP to verify DNS resolution.
Process Table
StepActionInput/QueryCoreDNS BehaviorOutput/Result
1Pod starts and sends DNS querynslookup kubernetes.defaultCoreDNS receives queryQuery received for kubernetes.default
2CoreDNS checks cachekubernetes.defaultNo cached entry foundCache miss
3CoreDNS queries Kubernetes APIRequest service IP for kubernetes.defaultAPI returns cluster IP10.96.0.1
4CoreDNS caches resultkubernetes.default -> 10.96.0.1Stores IP in cacheCache updated
5CoreDNS returns IP to Pod10.96.0.1Pod receives IPnslookup output shows 10.96.0.1
6Pod connects to serviceConnect to 10.96.0.1Connection establishedService reachable
7Pod sends repeated DNS querynslookup kubernetes.defaultCoreDNS checks cacheCache hit, returns 10.96.0.1
8Pod sends DNS query for unknown namenslookup unknown.svc.cluster.localCoreDNS checks cache and APIName not found error
9ExitNo more queriesEnd of DNS resolution processProcess complete
💡 DNS queries stop or unknown names cause resolution failure
Status Tracker
VariableStartAfter Step 3After Step 4After Step 7Final
Cacheempty{'kubernetes.default': '10.96.0.1'}{'kubernetes.default': '10.96.0.1'}{'kubernetes.default': '10.96.0.1'}{'kubernetes.default': '10.96.0.1'}
Pod DNS Querynonekubernetes.defaultkubernetes.defaultkubernetes.defaultunknown.svc.cluster.local
Resolved IPnone10.96.0.110.96.0.110.96.0.1none
Key Moments - 3 Insights
Why does CoreDNS query the Kubernetes API after a cache miss?
Because CoreDNS does not have the IP cached, it must ask the Kubernetes API to get the current IP for the service name, as shown in step 3 of the execution_table.
What happens when a Pod queries a DNS name that does not exist?
CoreDNS tries to find the name in cache and API but fails, returning a name not found error, as shown in step 8 of the execution_table.
How does caching improve DNS query performance in Kubernetes?
Caching stores resolved IPs so repeated queries return immediately without API calls, demonstrated by the cache hit in step 7.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3. What does CoreDNS do after a cache miss?
AQueries the Kubernetes API for the service IP
BReturns an error immediately
CSends the query to an external DNS server
DIgnores the query
💡 Hint
Refer to the 'CoreDNS Behavior' column at step 3 in the execution_table
At which step does CoreDNS cache the resolved IP address?
AStep 2
BStep 4
CStep 6
DStep 8
💡 Hint
Look for the step where 'CoreDNS caches result' in the 'Action' column
If the Pod queries 'unknown.svc.cluster.local', what will CoreDNS return?
AThe IP address of the Kubernetes service
BA cached IP from previous queries
CA name not found error
DThe IP of the Pod itself
💡 Hint
Check the 'Output/Result' column at step 8 in the execution_table
Concept Snapshot
DNS in Kubernetes uses CoreDNS to resolve service and pod names.
Pods send DNS queries to CoreDNS.
CoreDNS checks cache first, then Kubernetes API if needed.
Resolved IPs are cached for faster future queries.
Unknown names return errors.
This enables service discovery inside the cluster.
Full Transcript
In Kubernetes, DNS resolution is handled by CoreDNS. When a Pod sends a DNS query, CoreDNS first checks its cache. If the IP is not cached, CoreDNS queries the Kubernetes API to get the IP address of the requested service or pod. It then caches this IP for future queries. The Pod receives the IP and can connect to the service. If the DNS name does not exist, CoreDNS returns a name not found error. This process allows Pods to discover services by name within the cluster efficiently.