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?
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With