How does DNS work in Kubernetes?

· Category: Kubernetes

Short answer

Kubernetes uses CoreDNS as its cluster DNS server. It resolves service names to ClusterIPs and Pod names to Pod IPs, enabling applications to discover services without hardcoding IP addresses.

How it works

CoreDNS runs as a Deployment in the kube-system namespace. Each Pod's /etc/resolv.conf points to the CoreDNS service. DNS names follow the format service.namespace.svc.cluster.local. Short names resolve within the same namespace.

Example

# Inside a Pod
curl http://backend
curl http://backend.default
curl http://backend.default.svc.cluster.local

Custom DNS config:

dnsPolicy: "None"
dnsConfig:
  nameservers:
    - 8.8.8.8
  searches:
    - default.svc.cluster.local

Why it matters

Reliable DNS is essential for microservices communication. It decouples services from IP addresses, supports load balancing, and integrates with service mesh for advanced traffic management.

Common issues

  • DNS resolution failures often indicate CoreDNS is not running.
  • ndots:5 in resolv.conf can cause unnecessary external DNS queries.
  • Custom DNS policies may break internal service discovery.