CoreDNS is a DNS server that runs inside Kubernetes and is responsible for service discovery — i.e., translating service names (like my-service.default.svc.cluster.local) into IP addresses.
What CoreDNS Does
In a Kubernetes cluster:
- Every Pod and Service gets its own DNS name.
- CoreDNS listens for DNS queries from Pods (via /etc/resolv.conf).
- It looks up the name in the cluster’s internal DNS records and returns the correct ClusterIP or Pod IP.
So if a Pod tries to reach mysql.default.svc.cluster.local, CoreDNS will resolve it to the IP of the mysql service.
How It Works
Runs as a Deployment in the kube-system namespace.
Has a Service called kube-dns (for backward compatibility).
Uses a ConfigMap (coredns) to define how DNS queries are processed.
Listens on port 53 (UDP/TCP), the standard DNS port.
Has a Service called kube-dns (for backward compatibility).
Uses a ConfigMap (coredns) to define how DNS queries are processed.
Listens on port 53 (UDP/TCP), the standard DNS port.
Example CoreDNS ConfigMap snippet:
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
}
prometheus :9153
forward . /etc/resolv.conf
cache 30
loop
reload
loadbalance
}
Key Plugins
CoreDNS is modular — it uses plugins for specific functionality:
- kubernetes: handles DNS for cluster Services/Pods.
- forward: forwards queries to upstream resolvers for external domains.
- cache: caches responses for faster resolution.
- prometheus: exposes metrics for monitoring.
- health: adds a health endpoint.
Why It Matters
Without CoreDNS, Pods can’t resolve service names.
It’s essential for communication between microservices.
It’s a critical cluster component — if it breaks, DNS resolution (and often your workloads) fail.
Common Commands
Check CoreDNS pods:
kubectl get pods -n kube-system -l k8s-app=kube-dns
View CoreDNS logs:
kubectl logs -n kube-system -l k8s-app=kube-dns
Edit CoreDNS config:
kubectl -n kube-system edit configmap coredns
---

No comments:
Post a Comment