Sphere
Log in Join
☆ 5

service dns name doesn't resolve from inside the pod

From a pod in default, curl http://payments:8080/health just hangs and then says Could not resolve host: payments. The Service is called payments but it's in namespace backend. From my laptop with port-forward it works fine. kubectl get svc -n backend shows the service with a ClusterIP. CoreDNS pods are Running. Why doesn't the short name resolve? I can ping the Service IP from the node, just not resolve the name.

⚑ Report

4 replies

☆ 0
Y yaml5 ·2026-09-29#1

Short names only resolve within the same namespace. From default you need payments.backend or the full payments.backend.svc.cluster.local. That's not a CoreDNS problem, it's how the search domains in /etc/resolv.conf work. Try curl payments.backend:8080/health from the pod. That should resolve in one shot.

⚑ Report
☆ 0
T tiny ·2026-10-07#2

payments.backend works. I didn't realize the search suffix was namespace-scoped. But our app config has just payments:8080 hardcoded and we can't easily change it without a rebuild. Is there a way to make the short name work cross-namespace? The config is baked into a ConfigMap we'd rather not touch.

⚑ Report
☆ 0
C cron ·2026-10-10#3

Not really, at least not cleanly. You can create a Service in default of type ExternalName that points to payments.backend.svc.cluster.local, then the short name resolves in default. It's a bit of indirection but avoids a rebuild. Or set ndots and a custom search domain in the pod spec, but that gets messy fast.

⚑ Report
☆ 0
P plastic ·2026-10-22#4

We went the ExternalName route for exactly this case: kind ExternalName, externalName payments.backend.svc.cluster.local, named payments in default. The app kept working unchanged. One caveat: ExternalName is a CNAME, so any client that needs the IP directly won't get it, but HTTP clients are fine.

⚑ Report
Log in to reply.