Checking for particular pod status before each initialisation of another pod

10/2/2019

Assume deployment like that:

  1. Deployment contains two types of pods Config and App
  2. Each App pod to start needs to have access to Config pod
  3. There is always only one Config pod
  4. Already launched App pods can work without access to Config pod service

Situation I would like to manage:

  1. Node containing some of App pods and Config pod going down for any reason
  2. On another Node first starts Config pod
  3. After Config pod is successfully started App pods are launched

Already read about:

  1. InitContainers - couldn't find an information if Config pod would be of type Init if in above situation it would rerun - I think not
  2. StatueFullSet - I cannot find a way how this could help me in that situation

From my perspective I was thinking about a loop for App pods before running target application, that would wait for Config pod to come up and in case of unavailability after timeout force them to fail. But I'm not sure if that is best practice, would like better to handle this with Kubernetes configuration rather that with such script.

-- kamracik
kubernetes

1 Answer

10/3/2019

You would use either code in your app or an initContainer to block until a config pod is available. Combine this with a readinessProbe that checks if the app is up. Doing the block-and-retry loop in your own code is a bit more work but recommended since you can more carefully control the behavior. This means that app pods can launch whenever, but they won't be marked as ready for traffic until the initialize.

-- coderanger
Source: StackOverflow