I have 3 services that are based on the same image, they're basically running the same app in 3 different configurations. 1 service is responsible for running migrations and data updates which the other 2 services will need. So I need this 1 service to be deployed first before the other 2 will be deployed. Is there any way to do this?
3 Answers
I would look for a solution outside of Kubernetes.
Assuming that you have a release pipeline to deploy the changes, you could have a step to migrate and update the database. If the migration step succeeds, then deploy all the new services.
If you really have to use K8S, see the InitContainers doc.

- 1,920
- 2
- 10
- 19
I assume that the two services which are dependent on service 1 are either Pod
, Deployment
or ReplicaSet
. So, make use of Init Containers.
Here is an example that will make a pod wait until the dependent services are up and running. busybox
is most common image used for init containers that supports variety of linux commands that will help you check the status of dependent services.

- 496
- 7
- 11
-
Since all 3 services are the same repository. When we update the image version in fluxcd, Isn't it up to K8s to decide which service will go first? And then say service 2 is deployed first, it would still get a successful response from the older pod of service 1 right? – AshanPerera Oct 28 '22 at 10:10
-
Yes. I follow you. In that case you will have to go for something like blue-green deployment kind of service rollout. Example: https://www.haproxy.com/blog/rolling-updates-and-blue-green-deployments-with-kubernetes-and-haproxy/ – Amit Oct 28 '22 at 10:53
-
thanks, I used the init containers and it works as expected – AshanPerera Nov 09 '22 at 07:27
In flux there is an option to define the sequence of applications to be deployed. With spec.dependsOn you can specify that the execution of a Kustomization follows another. When you add "dependsOn" entries to a Kustomization, that Kustomization is applied only after all of its dependencies are ready.
You can add under the spec of kustomization
spec:
dependsOn:
- name: dependency-kustomization

- 1
- 2