I have been using Openshift/Kubernates for some time and this has been the understanding. For service to service communication
- use DNS name of
${service-name}if they are under the same namespace - use DNS name of
${service-name}.${namespace}.svc.cluster.localif they are from different namespaces (network is joined)
Recently i was introduced with the topic of "we should add a dot after the svc.cluster.local to make it FQDN, for better DNS lookup speed". Done some testing and indeed with lookup is much faster with the dot. (~100ms without dot, 10ms with dot)
After some research, it was caused by the default dns setting from the kubernates
sh-4.2$ cat /etc/resolv.conf
search ${namespace}.svc.cluster.local svc.cluster.local cluster.local
nameserver X.X.X.X
options ndots:5
the ndots = 5 will perform a local search (sequential) if the dns name does not contain 5 dots.
In the case of ${service-name}.${namespace}.svc.cluster.local, the local search will be as such
${service-name}.${namespace}.svc.cluster.local+${namespace}.svc.cluster.local// FAILED LOOKUP${service-name}.${namespace}.svc.cluster.local+svc.cluster.local// FAILED LOOKUP${service-name}.${namespace}.svc.cluster.local+cluster.local// FAILED LOOKUP${service-name}.${namespace}.svc.cluster.local// SUCCESS LOOKUP
And for ${service-name}.${namespace}.svc.cluster.local., the local search will be as such
${service-name}.${namespace}.svc.cluster.local// SUCCESS LOOKUP
References
Questions:
- Since the
ndots = 5is the default setting for kubernetes, why${service-name}.${namespace}.svc.cluster.local.is not documented on the official side ? - Should we change all service call to
${service-name}.${namespace}.svc.cluster.local.? any potential downsides ?