Wrong name, or the Service is in another namespace
no such host NXDOMAIN kubernetes.default resolves
What you see
$ kubectl logs deploy/checkout -n shop | tail -1
Post "http://payments/charge": dial tcp: lookup payments on 172.20.0.10:53: no such host$ kubectl debug -it checkout-7d4b9c6f5-x2kqp -n shop --image=registry.k8s.io/e2e-test-images/jessie-dnsutils:1.3 -- nslookup payments
Server: 172.20.0.10
Address: 172.20.0.10#53
** server can't find payments: NXDOMAINNXDOMAIN is an answer: CoreDNS is up and reachable, and it says the name doesn't exist. A short name is tried with the Pod's own namespace first (payments.shop.svc.cluster.local), then the other search domains, so payments only finds a Service in shop.
Confirm
# Does the Service exist, and in which namespace?
kubectl get service -A --field-selector metadata.name=payments
# The search domains the client Pod uses
kubectl exec deploy/checkout -n shop -- cat /etc/resolv.conf
# The name with its namespace, from the same Pod
kubectl debug -it checkout-7d4b9c6f5-x2kqp -n shop --image=registry.k8s.io/e2e-test-images/jessie-dnsutils:1.3 -- nslookup payments.billing.svc.cluster.localIf get service -A finds nothing, the Service doesn't exist under that name: a typo, not deployed yet, or another cluster. If the full name resolves and the call then fails with refused or a timeout, DNS is done: go to the Service not reachable playbook.
Fix
- Call the Service with its namespace:
payments.billingworks through the search list, andpayments.billing.svc.cluster.localis the full name. Put it in the app's config. - Fix the typo, or deploy the Service. A Service name resolves as soon as the Service exists; a Pod's own name doesn't resolve unless it sets
hostnameandsubdomainbehind a headless Service. - A cross-namespace call also has to pass any Network Policies in the target namespace; that failure is a timeout on the connection, after the name resolved.
Prevent
- Use
<service>.<namespace>or the full.svc.cluster.localname for anything outside the Pod's own namespace, even when both happen to share one today. - In the deploy pipeline, smoke-test the app's configured hostnames from a Pod in its namespace.