What if your apps could always find each other without you lifting a finger?
Why DNS in Kubernetes (CoreDNS)? - Purpose & Use Cases
Imagine you have many apps running on different computers, and you want them to talk to each other. Without DNS, you must remember and type each app's exact address every time.
This manual way is slow and confusing. If an app moves or changes its address, you must update every place that uses it. This causes mistakes and breaks communication.
CoreDNS in Kubernetes automatically handles all app addresses. It gives each app a simple name and keeps track of where it lives. Apps can find each other easily without manual updates.
curl http://10.0.0.15:8080 curl http://10.0.0.20:8080
curl http://myapp.default.svc.cluster.local curl http://otherapp.default.svc.cluster.local
CoreDNS makes app communication smooth and reliable by turning complex addresses into easy names that always work.
When you deploy a new version of a service, CoreDNS updates the address behind the scenes, so other services keep working without any changes.
Manual IP management is slow and error-prone.
CoreDNS automates service discovery with easy names.
This keeps apps connected even when they move or change.
Practice
Solution
Step 1: Understand CoreDNS function
CoreDNS acts as the DNS server inside Kubernetes, resolving names of services and pods.Step 2: Compare with other options
Managing images, scheduling pods, and monitoring are done by other components like container registries, kube-scheduler, and metrics servers.Final Answer:
To provide DNS resolution for services and pods inside the cluster -> Option BQuick Check:
CoreDNS = DNS resolution inside Kubernetes [OK]
- Confusing CoreDNS with pod scheduling
- Thinking CoreDNS manages container images
- Assuming CoreDNS monitors resources
Solution
Step 1: Identify CoreDNS configuration storage
The CoreDNS configuration is stored in a ConfigMap named 'coredns' inside the 'kube-system' namespace.Step 2: Eliminate other options
Deployment runs CoreDNS pods but does not hold config; Secrets store sensitive data; ServiceAccounts manage permissions.Final Answer:
ConfigMap named coredns in kube-system namespace -> Option CQuick Check:
CoreDNS config = ConfigMap coredns in kube-system [OK]
- Confusing ConfigMap with Secret
- Looking in default namespace instead of kube-system
- Thinking Deployment holds config data
nslookup kubernetes.default.svc.cluster.local. What is the expected result?Solution
Step 1: Understand the DNS query
The domain 'kubernetes.default.svc.cluster.local' is the default Kubernetes API service DNS name inside the cluster.Step 2: Determine expected DNS resolution
CoreDNS resolves this to the IP address of the Kubernetes API service, not the pod or CoreDNS pod IP.Final Answer:
An IP address of the Kubernetes API service -> Option AQuick Check:
Default service DNS resolves to API server IP [OK]
- Expecting pod IP instead of service IP
- Assuming CoreDNS pod IP is returned
- Thinking query fails inside pod
Solution
Step 1: Recognize CoreDNS config reload behavior
CoreDNS pods need to reload the ConfigMap changes, which usually requires restarting the pods.Step 2: Evaluate other options
Deleting unrelated pods or reinstalling the cluster is unnecessary; changing DNSPolicy may break cluster DNS.Final Answer:
Restart the CoreDNS pods to reload the new config -> Option AQuick Check:
CoreDNS pods restart reloads ConfigMap changes [OK]
- Deleting unrelated pods expecting DNS fix
- Reinstalling cluster unnecessarily
- Changing pod DNSPolicy incorrectly
myapp.local inside your Kubernetes cluster using CoreDNS. Which step is required?Solution
Step 1: Understand how to add custom DNS entries in CoreDNS
CoreDNS supports a hosts plugin where you can add static hostname-to-IP mappings in its ConfigMap.Step 2: Evaluate other options
Creating a Service named myapp.local won't create a DNS entry for that domain; modifying kubelet hosts is manual and not scalable; pod names don't create DNS entries.Final Answer:
Add a hosts plugin entry in the CoreDNS ConfigMap with myapp.local mapping -> Option DQuick Check:
Custom DNS via hosts plugin in CoreDNS ConfigMap [OK]
- Thinking Service name creates arbitrary DNS names
- Modifying node hosts files manually
- Assuming pod names create DNS entries
Ready to prove it?
Pass the test and this pattern moves unknown
