Amazon EKS — Services & DNS
Services & DNS
Kubernetes Services provide stable networking endpoints for your pods. CoreDNS handles service discovery so pods can find each other by name.
Service Types
| Type | Accessibility | Use Case |
|---|---|---|
| ClusterIP | Internal only | Default; internal microservice communication |
| NodePort | External via node IP:port | Testing; rarely used in production |
| LoadBalancer | External via AWS ELB/NLB | Production external access |
| ExternalName | DNS CNAME | Pointing to external services |
ClusterIP (Default)
apiVersion: v1
kind: Service
metadata:
name: backend
spec:
type: ClusterIP # Default
selector:
app: backend
ports:
- port: 80
targetPort: 8080
# Other pods can reach it via:
$ curl http://backend # Same namespace
$ curl http://backend.default # Cross-namespace (short)
$ curl http://backend.default.svc.cluster.local # FQDN
CoreDNS
CoreDNS runs as a Deployment in kube-system and provides DNS for all Services:
DNS Resolution
┌────────────────────────────────────────────────┐
│ Pod queries: "backend" │
│ │ │
│ ▼ │
│ CoreDNS (kube-system) │
│ Checks: backend.default.svc.cluster.local │
│ │ │
│ ▼ │
│ Returns: 172.20.45.67 (ClusterIP) │
└────────────────────────────────────────────────┘
DNS for Pods
# Pod DNS name (if hostname set):
<pod-ip-with-dashes>.<namespace>.pod.cluster.local
# Example: 10-0-1-11.default.pod.cluster.local
Troubleshooting DNS
# Test DNS resolution from a pod
$ kubectl run dns-test --image=busybox:1.36 --rm -it -- nslookup kubernetes
Server: 172.20.0.10
Address: 172.20.0.10:53
Name: kubernetes.default.svc.cluster.local
Address: 172.20.0.1
# Check CoreDNS pods
$ kubectl get pods -n kube-system -l k8s-app=kube-dns
# Check CoreDNS config
$ kubectl get configmap coredns -n kube-system -o yaml
Common Mistakes
| Mistake | Impact |
|---|---|
| Using pod IPs directly | Breaks when pods restart |
| Wrong targetPort | Service routes to wrong port |
| CoreDNS not running | All DNS resolution fails |
| Not using headless Services for StatefulSets | Can’t address individual pods |
What’s Next?
Secure pod communication: Network Policies.