<p>I have two containers，maybe A and B, which A should run before B, but A is a server application, which the final type is Running but not Complete, so I wonder in this way, will B be never executed? So how can I deal with it?</p>

edselwang
<p>If A and B are part of the same pod, then <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">initContainer</a> is the legacy way to establish ordering.</p>

<p>From the <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-states" rel="nofollow noreferrer">Kubernetes Pod lifecycle</a>, I suppose you mean "Running, but no Terminated"</p>

<p>A <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/" rel="nofollow noreferrer">pod liveness/readiness probe</a> is in your case a better fit, since the server will not accept request until ready. </p>

<p>Read "<a href="https://medium.com/faun/straight-to-the-point-kubernetes-probes-e5b23e267d9d" rel="nofollow noreferrer">Straight to the Point: Kubernetes Probes</a>" from <a href="https://twitter.com/petomalina" rel="nofollow noreferrer">Peter Malina</a></p>

<blockquote>
  <p>Both readiness and liveness probe run in parallel throughout the life of a container. </p>
  
  <ul>
  <li>Use the liveness probe to detect an internal failure and restart the container (e.g. HTTP server down). </li>
  <li>Use the readiness probe to detect if you can serve traffic (e.g. established DB connection) and wait (not restart) for the container. </li>
  </ul>
  
  <p>A dead container is also not a ready container.<br>
  To serve traffic, all containers within a pod must be ready.</p>
</blockquote>

<p>You can add a <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-readiness-gate" rel="nofollow noreferrer">pod readiness gate (stable from 1.14)</a> to specify additional conditions to be evaluated for Pod readiness.</p>

<p>Read also "<a href="https://blog.colinbreck.com/kubernetes-liveness-and-readiness-probes-how-to-avoid-shooting-yourself-in-the-foot/" rel="nofollow noreferrer">Kubernetes Liveness and Readiness Probes: How to Avoid Shooting Yourself in the Foot</a>" from <a href="https://blog.colinbreck.com/" rel="nofollow noreferrer">Colin Breck</a></p>

<p>"<a href="https://stackoverflow.com/a/53874319/6309">Should Health Checks call other App Health Checks</a>" compares that approach with the <a href="https://medium.com/@xcoulon/initializing-containers-in-order-with-kubernetes-18173b9cc222" rel="nofollow noreferrer">InitContainer approach</a></p>
