kubernetesdnsfqdn

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


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?


Solution

  • 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.