Question:
I have an init container that do some stuff that needs for the main container to run correctly, like creating some directories and a liveness probe that may fail if one of these directories were deleted. When the pod is restarted due to fail of liveness probe I expect that init container is also being restarted, but it won’t.This is what kubernetes documentation says about this:
If the Pod restarts, or is restarted, all init containers must execute again.
https://kubernetes.io/docs/concepts/workloads/pods/init-containers/Easiest way to prove this behavior was to use the example of the pod from k8s documentation, add a liveness probe that always fails and expect that init container to be restarted, but again, it is not behaving as expected.
This is the example I’m working with:
The pod is being restarted:
The question is how to force the init container to restart on pod restart.
Answer:
The restart number refers to container restarts, not pod restarts.init container need to run only once in a pos lifetime, and you need to design your containers like that, you can read this PR, and especially this comment
If you have better answer, please add a comment about this, thank you!