What's the DNS name for services in different namespaces in k8s?

10/14/2019

In namespace A, I have a service nginx running. In namespace B, I can use nginx.A or nginx.A.svc.cluster.local to get access to the nginx in namespace A.

So what's the difference between these two? Which one is more recommended? Why?

-- injoy
dns
fqdn
kubernetes

2 Answers

10/14/2019

Both forms are considered to be correct (compare with this article) and in majority of cases work fine however I could find a few issues on github when people encountered some problems related only to short names resolution e.g.:

https://github.com/kubernetes/dns/issues/109

https://github.com/kubernetes/kubernetes/issues/10014

As you can read in official Kubernetes documentation (ref1, ref2), it recommends use of the long form in case of reaching services across namespaces:

When you create a Service, it creates a corresponding DNS entry. This entry is of the form <service-name>.<namespace-name>.svc.cluster.local, which means that if a container just uses <service-name>, it will resolve to the service which is local to a namespace. This is useful for using the same configuration across multiple namespaces such as Development, Staging and Production. If you want to reach across namespaces, you need to use the fully qualified domain name (FQDN).

In my opinion it's much better to stick to FQDN (fully qualified domain name) standard and often being explicit is considered to be a better practice than being implicit.

-- mario
Source: StackOverflow

10/14/2019

These are equivalent. If you look at the default resolv.conf that is injected into every container:

search mynamespace.svc.cluster.local svc.cluster.local cluster.local mydomain
options ndots:5

you can see it will automatically query up the chain for you. This assumes you are using the default Linux DNS client behavior. If you have your own custom resolver then it may not understand the partial lookup syntax, though most do check resolv.conf.

-- coderanger
Source: StackOverflow