Can we decide pod failure based on one or 2 containers failure?

Viewed 363

If I have containers A and B in a pod.. Can i define the failure condition in a pod?? Let's say if container B is not up and running or if its status is exited then spin up another pod with the same set of containers ? An example of configuration file if any ?

1 Answers

A PodSpec has a restartPolicy field with possible values Always, OnFailure, and Never.If a container fails, it is restarted according to its restart policy. Other containers in the same Pod aren't affected. So it does not create a completely new pod if one of the containers fails.

The problem if you use pod is that it's not restarted into another node. For that you should use a higher level controller such as deployment.

Additionally you should define readiness and liveness probe for each container. So kubernetes will remove that container PORT from services if the probe fails.

So with all these you really don't need to worry about creating a new pod if one of the container fails.

Related