How Kubernetes establishes communication between Pods

Kubernetes provides a feature called service discovery. It gives containers their own IP addresses and a single DNS name and can load-balance across them.

Services are responsible for communication between pods. You can see in architecture where serviceIP is actually a key component for the service discovery. It consists of DNS mapping with Pod IP(iptables).

Example of Kubernetes services:

Below is an example of the services. This example is for mysql deployment.mysql-service.yml

Kubernetes Pods are mortal. A Kubernetes Service is an abstraction which defines a logical set of Pods and a policy by which to access them; sometimes called a micro-service. The set of Pods targeted by a Service is (usually) determined by a Label Selector.

Pod can access other Pods using fully classified DNS like:

"mysqlauth-service.production-cloud.svc.cluster.local:3306"

It consists structure like servicename.namespace.svc.cluster.local. Using environment variables are a good choice if microservice architecture is followed.

This is the standard way to communicate between the pods. K8S namespaces also plays the important role in terms of the communication. In Microservice architecture, it is possible to pass the environment variable to containerized image of the service. It is possible to pass the environment variable from K8S manifests. Check out our other blogs to know more about containers and K8S.