Every Service gets a DNS record:
text
<service>.<namespace>.svc.cluster.local ──▶ cluster IPCoreDNS serves these records. It runs in kube-system behind the kube-dns Service:
sh
kubectl get svc -n kube-systemWhat a Pod sees
Each Pod's /etc/resolv.conf points at CoreDNS and carries a search list:
text
search straits-abc.svc.cluster.local svc.cluster.local cluster.local
nameserver 10.96.0.10
options ndots:5Resolution of a short name walks the search list:
text
wget market-api
1. market-api.straits-abc.svc.cluster.local <- same namespace: found
2. market-api.svc.cluster.local
3. market-api.cluster.localSo inside a namespace, the bare Service name is enough.
Across namespaces
From namespace straits-abc-ops, market-api expands to market-api.straits-abc-ops.svc.cluster.local. That record does not exist. Use the namespace-qualified form:
text
market-api.straits-abc works (search list adds svc.cluster.local)
market-api.straits-abc.svc.cluster.local works (the FQDN)
market-api NXDOMAIN from another namespaceChecking from a Pod
sh
kubectl exec client -- nslookup market-api
kubectl exec client -- cat /etc/resolv.conf
kubectl exec client -- wget -qO- market-api.straits-abc.svc.cluster.local:8080/healthznslookup prints the name it resolved and the cluster IP. NXDOMAIN means the name does not exist as searched.