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
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.
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.
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.