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

4

20

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

Madrepore answered 17/5, 2018 at 6:56 Comment(1)
possible duplicate of #50325177, see point 2) in original question.Sindee
C
11

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.

Casebook answered 17/5, 2018 at 7:46 Comment(1)
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.Yesterday
P
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.

Pilsen answered 6/7, 2018 at 20:4 Comment(0)
D
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.

Discreet answered 10/9, 2018 at 5:50 Comment(0)
S
0

I have been working on such controller , need few more tests done and it will be published next week, utilizes deployment readiness statuses crds service accounts, cluster roles rolebindings etc.

Schleswigholstein answered 12/8, 2024 at 20:34 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.