Is there a way to create interdependent pods on Kubernetes cluster?

4/1/2020

Is there a way to create interdependent pods on kubernetes cluster. As in if a Pod A running a certain micro-service goes down then Pod B also goes down due to it. Actually i have an application in which there a certain micro-services which are dependent on rabbitmq(which i am running as a pod and exposed as a service for other pods(micro-services) to consume) I am looking for a solution where in if my rabbitmq pod goes down all my other pods also should stop due to it.

-- Mandeep Singh
dependencies
docker
kubernetes
microservices
rabbitmq

1 Answer

4/1/2020

The easiest thing to do here is just to have your service crash if it can't reach RabbitMQ or another dependency.

Kubernetes will restart it immediately, and if the cause of the failure was a network blip, everything will be okay again. But if RabbitMQ is actually down, the pod will crash again, and after a couple of retries the pod will be in CrashLoopBackOff state; Kubernetes will pause before trying to restart it.

At this point your RabbitMQ will be absent and your various pods will show CrashLoopBackOff. If you look at things like kubectl get pods you'll say "wait, something is really wrong", and kubectl logs on an individual pod will probably have a pretty clear backtrace saying "couldn't connect to RabbitMQ".

Once RabbitMQ recovers, the automatic restarts will (eventually) happen, and the whole system will come up again on its own.

-- David Maze
Source: StackOverflow