How to add pod dependency in kubernetes as like 'depends_on' in docker-compose.yml

5/17/2018

I need to start kubernetes pods in a sequence like pod2 should start only when pod1 is up and running.

we can do this in docker-compose.yml using depends_on

-- sam
devops
docker
kubernetes
kubernetes-helm

3 Answers

9/10/2018

You can use this pod-dependency-init-container that I have build. This will check if any pod with given labels is running before starting your pod.

-- Yogesh
Source: StackOverflow

7/6/2018

There isn't a direct equivalent to dependency with Kubernetes primitives, as a workaround you can implement a readiness probe that will render pod2 unusable until it sees pod1 up and running.

-- itaysk
Source: StackOverflow

5/17/2018

No, there is no built-in dependency management equivalent to depends_on available. In general, we assume loosely coupled services and as a good practice there should be no hard dependency in terms of start-up order, but retries and timeouts should be used. If you have to hardcode dependencies, you can use init containers. In your case, a init container in pod2 could simply query if pod1 (or better: the service in front of it) is ready in a while loop. The main container in pod2 is guaranteed only to be launched if and when the init container exits successfully.

-- Michael Hausenblas
Source: StackOverflow