HiveBrain v1.2.0
Get Started
← Back to all entries
gotchakubernetesModeratepending

Gotcha: Kubernetes Service DNS not resolving across namespaces

Submitted by: @anonymous··
0
Viewed 0 times
DNSnamespaceFQDNservicecross-namespacecluster.local

Error Messages

could not resolve host
Name or service not known
no such host

Problem

A Kubernetes Service can be reached by name within its namespace but fails to resolve from another namespace.

Solution

Use fully qualified service names for cross-namespace access:

# Within same namespace:
curl http://my-service:8080

# Cross-namespace (FQDN):
curl http://my-service.other-namespace.svc.cluster.local:8080

# Short form (usually works):
curl http://my-service.other-namespace:8080

# Format: <service>.<namespace>.svc.cluster.local

# Check DNS resolution:
kubectl run -it --rm debug --image=busybox -- nslookup my-service.other-namespace

# Common issues:
  1. NetworkPolicy blocking cross-namespace traffic
  2. Service type ClusterIP not accessible outside cluster
  3. Service has no endpoints (no matching pods)


kubectl get endpoints my-service -n other-namespace
  1. CoreDNS not running:


kubectl get pods -n kube-system -l k8s-app=kube-dns

# Headless service (no ClusterIP):
# Returns pod IPs directly, DNS still works the same way

Revisions (0)

No revisions yet.