**CoreDNS** is a flexible, extensible DNS server written in Go that serves as the default DNS resolver inside [[Kubernetes]] clusters. Every pod in Kubernetes resolves service names (like `my-service.my-namespace.svc.cluster.local`) through CoreDNS — it is the internal service discovery layer of the cluster. --- ### First Principle: Service names, not IP addresses, are how services find each other. CoreDNS makes service names work. In a Kubernetes cluster, pod IP addresses change constantly — pods are rescheduled, scaled, and replaced. CoreDNS watches the Kubernetes API for Service and Endpoint changes and serves DNS responses that always resolve to current, healthy endpoints. Services use names; CoreDNS handles the translation. --- ### Key Considerations - **Plugin-Based Architecture**: CoreDNS is built entirely on plugins. Each query passes through a configured chain of plugins — kubernetes (reads K8s service/endpoint data), forward (upstream DNS), cache, rewrite, health, metrics, etc. - **Kubernetes Plugin**: The `kubernetes` plugin watches the K8s API and serves `*.svc.cluster.local` and `*.pod.cluster.local` DNS names — the glue between DNS and Kubernetes service discovery. - **Forward Plugin**: CoreDNS forwards external DNS queries (e.g., `google.com`) to upstream resolvers — typically the host's configured DNS or [[PowerDNS]] for internal zones. - **Split DNS**: CoreDNS can serve different DNS answers for internal vs external queries — forwarding internal zones to [[PowerDNS]] and external zones to public resolvers. - **[[Prometheus]] Metrics**: CoreDNS exports [[Prometheus]] metrics — query rate, NXDOMAIN rate, cache hit rate, per-zone latency — making DNS performance observable. - **Custom Zones**: CoreDNS can serve custom DNS zones via file or etcd backends — useful for static internal DNS entries alongside Kubernetes-managed records. --- ### How It Fits ``` Pod DNS query (my-svc.my-ns.svc.cluster.local) → CoreDNS (kubernetes plugin → K8s API) → Returns current Service ClusterIP → External queries forwarded to [[PowerDNS]] / public resolvers ``` [[Kubernetes]] | [[PowerDNS]] | [[Prometheus]] | [[Open Source Hyperscaler MoC]]