CoreDNS and Internal DNS

Kubernetes provides an internal DNS service to enable service discovery using simple names instead of IP addresses. CoreDNS is the default DNS service used.

Service Discovery:

  • Services are automatically assigned a DNS name in the form of <service-name>.<namespace>.svc.cluster.local
  • Pods can resolve service names using DNS without needing to know IPs

Example:

# Resolves the backend service in the same namespace
ping backend

# Resolves a service in another namespace
ping backend.default.svc.cluster.local

CoreDNS Configuration:

CoreDNS runs as a Deployment in the kube-system namespace and is configured via a ConfigMap.

apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system
data:
  Corefile: |
    .:53 {
        errors
        health
        kubernetes cluster.local in-addr.arpa ip6.arpa {
          pods insecure
          fallthrough in-addr.arpa ip6.arpa
        }
        forward . /etc/resolv.conf
        cache 30
        loop
        reload
        loadbalance
    }

You can customize this Corefile to change DNS behavior or add external resolvers.

← PrevNext →