CKA — Cluster DNS

1 minute read

CoreDNS in Kubernetes

Every Kubernetes cluster runs a DNS server — CoreDNS — as a Deployment in the kube-system namespace. It provides DNS resolution for Services and Pods within the cluster.

# Check CoreDNS deployment
kubectl get deployment coredns -n kube-system

# Check CoreDNS pods
kubectl get pods -n kube-system -l k8s-app=kube-dns

DNS Record Format

Kubernetes creates DNS records automatically for Services and Pods:

Service DNS Records

Record Type Format Example
A record <service>.<namespace>.svc.cluster.local nginx-svc.default.svc.cluster.local
SRV record _<port-name>._<protocol>.<service>.<namespace>.svc.cluster.local _http._tcp.nginx-svc.default.svc.cluster.local

Pod DNS Records

Record Type Format Example
A record <pod-ip-dashed>.<namespace>.pod.cluster.local 10-244-0-5.default.pod.cluster.local

Short Names

Within the same namespace, you can use short names:

# Full FQDN
curl nginx-svc.default.svc.cluster.local

# Same namespace — just the service name works
curl nginx-svc

# Cross-namespace — need at least service.namespace
curl nginx-svc.other-namespace

DNS Resolution in Pods

Every Pod gets a /etc/resolv.conf that points to the CoreDNS ClusterIP:

# Check DNS configuration inside a Pod
kubectl exec -it nginx -- cat /etc/resolv.conf
# nameserver 10.96.0.10
# search default.svc.cluster.local svc.cluster.local cluster.local
# ndots:5

Pod DNS Policies

Policy Behavior
ClusterFirst (default) Use cluster DNS, fall back to upstream
Default Inherit DNS config from the node
None No auto-config, use dnsConfig in Pod spec
ClusterFirstWithHostNet For Pods with hostNetwork: true

Troubleshooting DNS

Test DNS Resolution

# Create a debug Pod
kubectl run dns-test --image=busybox:1.36 --rm -it -- nslookup kubernetes.default
# Expected: Returns the API server ClusterIP

# Test service resolution
kubectl run dns-test --image=busybox:1.36 --rm -it -- nslookup nginx-svc.default.svc.cluster.local

# More detailed DNS query
kubectl run dns-test --image=busybox:1.36 --rm -it -- nslookup -type=srv _http._tcp.nginx-svc.default.svc.cluster.local

Common DNS Issues

Symptom Likely Cause Fix
DNS resolution fails CoreDNS pods not running kubectl get pods -n kube-system -l k8s-app=kube-dns
Intermittent failures CoreDNS pod restarts Check CoreDNS logs: kubectl logs -n kube-system -l k8s-app=kube-dns
Cross-namespace fails Wrong DNS name format Use <svc>.<namespace> format
External DNS fails No upstream forwarder Check Corefile for forward directive

CoreDNS Configuration

# View the Corefile (CoreDNS config)
kubectl get configmap coredns -n kube-system -o yaml
# Default Corefile
.:53 {
    errors
    health {
        lameduck 5s
    }
    ready
    kubernetes cluster.local in-addr.arpa ip6.arpa {
        pods insecure
        fallthrough in-addr.arpa ip6.arpa
        ttl 30
    }
    prometheus :9153
    forward . /etc/resolv.conf
    cache 30
    loop
    reload
    loadbalance
}

Exam tip: DNS troubleshooting is common in the CKA exam. Know how to test DNS with nslookup from a debug Pod, check CoreDNS logs, and verify the CoreDNS ConfigMap.


Next: Hands-On Lab →

Updated: