How to create a dependency between Kubernetes Deployments or StatefulSets

6/13/2019

I have a couple of Stateful Sets, one is dependent on another one, I need the pods in the first Stateful Set to be in Ready state before the 2nd Stateful Set is started to be scaled.

I'm looking to see if there is a way to link the two Stateful Sets to achieve this in an automatic way, instead of me manually doing it. I have the same concern about Deployments as well.

Currently I don't use Helm or any other tools, just kubectl.

-- snagy
kubernetes
kubernetes-deployment
kubernetes-statefulset

1 Answer

6/13/2019

I would advise against doing this as it would increase coupling between different services.

A better way of handling your problem is for containers in the dependent service to check if the other service is available. If it isn't, it's ok to crash the container since Kubernetes provides self-healing by automatically restarting containers for you. This way, the dependent service will try to connect to the service and if the latter isn't available, then the dependent service will crash and try again later using exponential back-off.

-- Alassane Ndiaye
Source: StackOverflow