Kubernetes cluster by default automatically configures an internal DNS service to provide a mechanism for service discovery.
Applications will find and communicate with each other on Kubernetes clusters by service discovery.
Before K8S 1.11, the Kubernetes DNS Service was based on kube-dns, from 1.11, we have CoreDNS to address some security and stability concerns with Kubernetes.
The full DNS
A record of a Kubernetes service will look like:
And the pod will look like
E.g: In the current application, I am using Helm to generate application configuration and setup Postgres chart as a dependency. Postgres chart will have its own service. By using K8S DNS Service, I will able to connect the Postgres from the application, the Pg hostname in the application will be:
Want to know more about how CoreDNS or Kube-dns works, check the DO blog: https://www.digitalocean.com/community/tutorials/an-introduction-to-the-kubernetes-dns-service