15

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
  • 431
  • 1
  • 4
  • 16
  • possible duplicate of https://stackoverflow.com/questions/50324677/wait-for-other-deployments-to-start-running-before-other-can-be-created/, see point 2) in original question. – Const May 17 '18 at 08:55

3 Answers3

9

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
  • 13,162
  • 4
  • 52
  • 66
  • Why those two things should be mutually exclusive? Having retries doesn't mean there should be no dependencies. Having dependencies specified will likely speed-up start-up time of an app. I often see pods spinning in retries loop like mad until they finally make it in a correct order ... so not being able to specify dependencies easily is definitely not critical, but a nice to have feature. – IlliakaillI Jul 22 '22 at 22:56
2

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
  • 5,852
  • 2
  • 33
  • 40
0

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
  • 4,546
  • 2
  • 32
  • 41