How to Configure Pod initialization in a specific order in Kubernetes?

AVarf picture AVarf · Jul 8, 2019 · Viewed 8.4k times · Source

I want to know how I can start my deployments in a specific order. I am aware of initContainers but that is not working for me. I have a huge platform with around 20 deployments and 5 statefulsets that each of them has their own service, environment variables, volumes, horizontal autoscaler, etc. So it is not possible (or I don't know how) to define them in another yaml deployment as initContainers.

Is there another option to launch deployments in a specific order?

Answer

Alassane Ndiaye picture Alassane Ndiaye · Jul 8, 2019

It's possible to order the launch of initContainers in a Pod, or Pods that belong in the same StatefulSet. However, those solutions do not apply to your case.

This is because ordering initialization is not the standard approach for solving your issue. In a microservices architecture, and more specifically Kubernetes, you would write your containers such that they try to call the services they depend on (whether they are up or not) and if they aren't available, you let your containers crash. This works because Kubernetes provides a self-healing mechanism that automatically restarts containers if they fail. This way, your containers will try to connect to the services they depend on, and if the latter aren't available, the containers will crash and try again later using exponential back-off.

By removing unnecessary dependencies between services, you simplify the deployment of your application and reduce coupling between different services.