CoreDNS for Service Discovery
What you'll learn: How CoreDNS enables containers to find each other by name instead of hardcoding IP addresses in your Kubernetes cluster.
Why Service Discovery Matters
In a Kubernetes cluster, pods come and go constantly—they restart, scale up and down, and get reassigned new IP addresses. Hardcoding IPs would be a nightmare. You need a way for services to find each other reliably using human-friendly names, just like how you type "google.com" instead of memorizing IP addresses.
What CoreDNS Does
CoreDNS is Kubernetes' built-in DNS server that runs as a pod (usually in the kube-system namespace). It acts like a phone book for your cluster, translating service names into the current IP addresses of those services.
When a container needs to reach another service, it simply uses the service's name (like my-database-service). CoreDNS intercepts this request and returns the correct cluster IP address, allowing seamless communication.
How It Works in Practice
Think of CoreDNS as a receptionist at a large office building. When you ask for "the accounting department," the receptionist knows which floor and room they're currently in, even if they moved offices last week. You don't need to remember room numbers—just the department name.
CoreDNS watches the API server for changes to services and endpoints. When you create a service named my-app, CoreDNS automatically creates DNS records like:
my-app.default.svc.cluster.local(full name)my-app.default(namespace-scoped)my-app(within the same namespace)
Every pod automatically gets configured to use CoreDNS for name resolution through the kubelet.
Key Takeaway: CoreDNS provides automatic DNS-based service discovery in Kubernetes, allowing containers to communicate using stable service names instead of ever-changing IP addresses, making your applications resilient and easier to configure.