Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pod Communication

Tags:

kubernetes

How does the communication between two different pods happen in Kubernetes?

In my case I have two pods: frontend and backend, both have different containers. I want my frontend pod to communicate with the backend pod but I don't want to use backend pod's IP( i.e. hard coded).

Is it possible through services?

like image 804
Madhurima Mishra Avatar asked Dec 02 '15 17:12

Madhurima Mishra


2 Answers

A recommended method is with the DNS cluster add-on: http://kubernetes.io/docs/user-guide/services/#dns


Example from the 'guestbook' app:

https://github.com/kubernetes/kubernetes/blob/3574999fa34d54c47f43efd9eaff7e1c571c7910/examples/guestbook/php-redis/guestbook.php#L13

They use: $host = 'redis-master'; as the default method for communicating with the redis-master pod.

Which was defined in redis-master-service.yaml: https://github.com/kubernetes/kubernetes/blob/3574999fa34d54c47f43efd9eaff7e1c571c7910/examples/guestbook/redis-master-service.yaml

like image 127
Eyal Levin Avatar answered Oct 11 '22 20:10

Eyal Levin


Is it possible through services?

Yes, services are the recommended way to handle this. Once you have your services set up for each pod (or replication controller, as is recommended), you can find the service IP via the service environment variable, e.g. BACKEND_SERVICE_HOST and BACKEND_SERVICE_PORT for a "backend" service.

like image 29
Tim Allclair Avatar answered Oct 11 '22 19:10

Tim Allclair