Lesson 10 / 25
DNS and Service Discovery
Find services by name.
service.namespace.svc.cluster.local
Cluster DNS (CoreDNS) gives every Service a name: web from the same namespace, web.shop-prod from another, or fully web.shop-prod.svc.cluster.local. Applications should connect by these names, configured through environment variables or ConfigMaps, never by IP. Headless Services (clusterIP: None) return the individual pod addresses instead of one virtual IP, used by StatefulSets for stable per-pod names such as db-0.db.
Names a pod can use
From a pod in namespace shop-prod.
web Service "web" in the same namespace
web.shop-prod explicit namespace
web.shop-prod.svc.cluster.local fully qualified
payments.billing Service "payments" in namespace "billing"
db-0.db.shop-prod.svc.cluster.local pod 0 of StatefulSet "db" via headless Service "db"Configure names, not addresses
Put service URLs in configuration (http://web.shop-prod) so moving or scaling pods never breaks clients.
Quick check: What does a headless Service return in DNS?
- The individual pod addresses instead of a single virtual IP
- Nothing
- The node's IP only
- A public IP
Answer
The individual pod addresses instead of a single virtual IP — Used for stable per-pod identities.