Pod and Service DNS naming schema

2 min read

Kubernetes provides a DNS to be used to locate other pods or services instead of using it's IP address. The default cluster domain is cluster.local but we can change it if we like.

Every time a Pod is created it gets registered on the Kubernetes DNS using the following naming convention:

<pod>.<namespace>.pod.cluster.local

For example, for a pod with the IP 10.12.16.24 on the namespace demo it would create the following record:

10-12-16-24.demo.pod.cluster.local

Given that the DNS name also have the IP maybe for pods it's not going to be that useful after all. On the other hand, for Service objects it gets more interesting. It uses the following naming schema:

<svc name>.<namespace>.svc.cluster.local

Hence, if we have a service called prometheus-server on the namespace monitoring, the DNS that would be registered is:

prometheus-server.monitoring.svc.cluster.local

These FQDN domains names can be used from within any namespace in the cluster, but if the communication is within the same namespace it can use just the service name. This is achieved by including a search option on the resolv.conf file with all the possible domain suffixes:

search namespace.svc.cluster.local svc.cluster.local cluster.local

Posted on 18/06/2021

Categories