K8s by Example: DNS & Service Discovery
| Kubernetes runs CoreDNS for internal name resolution. Every Service gets a DNS A record automatically. Pods resolve Service names to ClusterIPs without hardcoding addresses. |
| service.yaml | |
| Services automatically get DNS records. This Service gets DNS: | |
| terminal | |
| DNS resolution from shortest to FQDN. Same namespace: just service name. Cross-namespace: | |
| terminal | |
| Services also get SRV records for named ports. SRV records contain port information, useful for dynamic port discovery. | |
| headless-service.yaml | |
| Headless Services ( | |
| terminal | |
| StatefulSet Pods get stable, predictable DNS names via headless Services. Each Pod gets its own A record: | |
| pod-dns-config.yaml | |
| Pod DNS policy controls how Pods resolve names. | |
| terminal | |
| CoreDNS configuration is in a ConfigMap in kube-system. Customize for external DNS forwarding, custom domains, or caching. Pods get | |
| terminal | |
| Debug DNS issues by checking CoreDNS pods, testing resolution from within the cluster, and verifying Service endpoints exist. Common issue: ndots setting causes external lookups to fail. | |
| pod-dns-optimized.yaml | |
| The default | |
| For Alpine/musl-based images, add | |
| terminal | |
| Scale CoreDNS for large clusters. Recommended: 1 CoreDNS pod per 10-20 nodes. Monitor CPU usage and increase replicas or resources if queries are slow. | |
Index | Use arrow keys to navigate