Networking: Services, DNS, and IngressLesson 3.2
Kubernetes DNS: how Pods discover each other by name
CoreDNS, service DNS format, FQDN structure, cross-namespace DNS, Pod DNS, ndots configuration, headless services, DNS for StatefulSets
Every Service Gets a DNS Name
Kubernetes runs CoreDNS inside the cluster. Every Service automatically gets a DNS entry. Pods can reach services by name without knowing IP addresses.
DNS Name Format
# Short name (within same namespace)
http://backend-svc
# Full name (cross-namespace)
http://backend-svc.production.svc.cluster.local
# ^name ^namespace ^constant suffix
# Reaching a service in a different namespace
curl http://payment-api.billing.svc.cluster.local/chargeTesting DNS from Inside a Pod
# Run a debug pod with DNS tools
kubectl run dns-test --image=busybox:1.35 --restart=Never -it -- sh
# Inside the pod:
nslookup backend-svc
nslookup backend-svc.production.svc.cluster.local
# Check your pod's DNS config
cat /etc/resolv.confHeadless Services
Set clusterIP: None to create a headless Service. Instead of a virtual IP, DNS returns the individual Pod IPs directly. This is how StatefulSets expose stable per-pod DNS names like postgres-0.postgres-svc.default.svc.cluster.local — essential for databases and leader-election scenarios.
spec:
clusterIP: None # headless
selector:
app: postgres