How to Fix CoreDNS Kubernetes DNS Resolution Error
In this tutorial, you'll learn about How to Fix CoreDNS Kubernetes DNS Resolution Error. We cover key concepts, practical examples, and best practices.
CoreDNS pods are in CrashLoopBackOff or pods cannot resolve Kubernetes service names — CoreDNS configuration is missing the Kubernetes plugin or it cannot reach the Kubernetes API server.
The Problem
$ kubectl run test --image=busybox -- nslookup kubernetes.default.svc.cluster.local
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
nslookup: can't resolve 'kubernetes.default.svc.cluster.local'
Step-by-Step Fix
Step 1: Check CoreDNS pod status
kubectl get pods -n kube-system -l k8s-app=kube-dns
Step 2: View CoreDNS logs
kubectl logs -n kube-system -l k8s-app=kube-dns
Step 3: Fix CoreDNS ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: kube-system
data:
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
}
Step 4: Check CoreDNS service
kubectl get svc -n kube-system kube-dns
# Expected CLUSTER-IP: 10.96.0.10
Step 5: Test DNS resolution
kubectl run dns-test --image=busybox --rm -it --restart=Never -- \
nslookup kubernetes.default
Step 6: Scale up CoreDNS
kubectl scale deployment -n kube-system coredns --replicas=3
Prevention Tips
- Run at least 2 CoreDNS replicas for high availability
- Monitor CoreDNS metrics via Prometheus
- Set resource limits on CoreDNS pods
- Use pod anti-affinity to spread CoreDNS across nodes
Common Mistakes with kubernetes error
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'causing stack overflow on large lists
These mistakes appear frequently in real-world COREDNS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro