Service Discovery & CoreDNS
Key Takeaways for AI & Readers
- Naming over IPs: Kubernetes uses Service Names for communication, allowing for stable networking even as individual Pod IPs change.
- CoreDNS Automation: The cluster's built-in DNS server automatically creates and maintains records for every Service.
- Service FQDN: The full address of a service follows a standard pattern:
service.namespace.svc.cluster.local. - Kubelet Integration: The Kubelet automatically configures every container's
/etc/resolv.confto point to CoreDNS.
In Kubernetes, you never hardcode IP addresses. Instead, you use the Service Name. But how does a container know that auth-service actually means 10.96.0.15?
1. Internal DNS Trace
Visualize how a request is resolved inside the cluster.
📦
Client Pod
📋
CoreDNS
Every Pod's
/etc/resolv.conf points to the CoreDNS Service IP. CoreDNS watches the K8s API and automatically maps service names to their ClusterIPs.2. CoreDNS
Every cluster has a built-in DNS server called CoreDNS.
- The Controller: CoreDNS watches the Kubernetes API for new Services.
- The Records: When a Service is created, CoreDNS automatically creates a DNS record:
my-service.my-namespace.svc.cluster.local.
3. How Pods find DNS
When the Kubelet starts a container, it injects a file: /etc/resolv.conf.
nameserver 10.96.0.10 # This is the CoreDNS ClusterIP
search default.svc.cluster.local svc.cluster.local cluster.local
This tells the OS: "If you can't find a host, ask the Kubernetes DNS server."