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?
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.
A recommended method is with the DNS cluster add-on: http://kubernetes.io/docs/user-guide/services/#dns
Example from the 'guestbook' app:
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