How DNS service works in the Kubernetes?

6/13/2019

I am new to the Kubernetes, and I'm trying to understand that how can I apply it for my use-case scenario. I managed to install a 3-node cluster on VMs within the same network. Searching about K8S's concepts and reading related articles, still I couldn't find answer for my below question. Please let me know if you have knowledge on this:

I've noticed that internal DNS service of K8S applies on the pods and this way services can find each other with hostnames instead of IPs.

Is this applicable for communication between pods of different nodes or this is only within the services inside a single node? (In other words, do we have a dns service on the node level in the K8S, or its only about pods?)

The reason for this question is the scenario that I have in mind:

I need to deploy a micro-service application (written in Java) with K8S. I made docker images from each service in my application and its working locally. Currently, these services are connected via pre-defined IP addresses. Is there a way to run each of these services within a separate K8S node and use from its DNS service to connect the nodes without pre-defining IPs?

-- Maryam Tavakkoli
dns
kubernetes

1 Answer

6/13/2019

A service serves as an internal endpoint and (depending on the configuration) load balancer to one or several pods behind it. All communication typically is done between services, not between pods. Pods run on nodes, services don't really run anything, they are just routing traffic to the appropriate pods.

A service is a cluster-wide configuration that does not depend on a node, thus you can use a service name in the whole cluster, completely independent from where a pod is located.

So yes, your use case of running pods on different nodes and communicate between service names is a typical setup.

-- Markus Dresch
Source: StackOverflow