Skip to content

Pod restart policies

Pod restart policies are configurations in Kubernetes that dictate how the kubelet handles containers within a Pod when they terminate.^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md] These policies are defined by the spec.template.spec.restartPolicy field within a Pod specification^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md] and are essential for maintaining application availability and reliability.

Policy Types

There are three specific values that can be assigned to the restart policy^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md]:

  • Always: The Pod is restarted whenever it terminates^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md]. This is the default setting^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md].
  • OnFailure: The Pod is restarted only if it terminates with an error (non-zero exit status)^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md].
  • Never: The Pod is never restarted, regardless of the exit status^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md].

Behavior and Mechanism

The restart policy specifically governs actions taken by the kubelet on the same node^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md]. When a container exits and needs to be restarted according to the policy, the kubelet initiates a restart following an exponential backoff delay strategy^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md]. This delay starts at 10 seconds and doubles with each attempt (10s, 20s, 40s, etc.) up to a maximum limit of 5 minutes^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md]. The backoff timer is reset if the container runs successfully for 10 minutes^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md].

Controller Constraints

Different Kubernetes controllers impose specific constraints on allowable restart policies based on their intended operational nature^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md]:

  • Job: Designed for one-off tasks (e.g., batch computation), a Job controller may only use OnFailure or Never^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md].
  • ReplicationController, ReplicaSet, Deployment: These controllers are intended for long-running services and must use Always^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md].
  • DaemonSet: Since a DaemonSet ensures a Pod runs on every node, it also requires the Always policy^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md].

Sources

^[400-devops__06-Kubernetes__k8s-ithelp__Day10__README.md]