Search code examples
kubernetesopenshift

Configuring restartPolicy for a container in a multi container pod


In my kubernetes yaml(in openshift env) I have defined two containers.

Also, spec section has restartPolicy set as Always.

spec:
  restartPolicy: Always

I want one of the container to have restartPolicy as Never.

When I try to set so in that container section, I see that it gets removed when I save yaml.

Whats the correct way of doing it?


Solution

  • In Kubernetes, the restartPolicy is set at the pod level and not at the individual container level. This means all containers within the same pod must share the same restartPolicy. This design is based on the idea that a pod is a unit of deployment that encapsulates the containers which should share the same lifecycle, scheduling, and runtime context.

    That is why you see the field gets removed when you save your manifest file.

    If you require different restart policies for different containers, you might need to separate them into different pods, each with its own appropriate restartPolicy.

    You can see a more detailed explanation here.