Why container order is important in K8s-Pod in yaml file


Basically, as i have learned (still learning) Kubernetes and people say by creating object type Pod, main container which has core application code, should come first in yaml file. I did not understand why?

PS: sure i read Pod Priority, but still it's not clear to me


1 Answer


It is up to you how to configure pods definition config file and which container is put first because it is not important which container you will define first on its execution order.

If you want to run on container before another simply use init containers. A Pod can have multiple containers running apps within it, but it can also have one or more init containers, which are run before the app containers are started. Init containers have separate images from app containers, they have some advantages for start-up related code. Init containers are exactly like regular containers, except:

  • init containers always run to completion
  • each init container must complete successfully before the next one starts.

You can define priority for your pods defining priority class but it is connected with pods scheduling time not execution. In Kubernetes 1.9 and later, when Pod priority is enabled, scheduler orders pending Pods by their priority and a pending Pod is placed ahead of other pending Pods with lower priority in the scheduling queue. As a result, the higher priority Pod may be scheduled sooner than Pods with lower priority if its scheduling requirements are met. If such Pod cannot be scheduled, scheduler will continue and tries to schedule other lower priority Pods.

Official documentations: kubernetes-pods-priority, init-containers.

-- MaggieO
Source: StackOverflow