2 min read | by Jordi Prats
When defining objects that contain a pod template (such a Deployment or a Job) but also when defining a plain pod we can control under which circumstances a pod will be restarted
The container restart policy can be controlled using restartPolicy on the spec at the same level where we define the containers:
apiVersion: batch/v1
kind: Job
metadata:
name: demo-restartPolicy-job
spec:
backoffLimit: 2
template:
metadata:
name: demo-restartPolicy-pod
spec:
containers:
- name: demo
image: sonarsource/sonar-scanner-cli
restartPolicy: Never
Since the restartPolicy is defined at the same level as all the containers, it applied at the Pod level. We can set it to:
If we are not setting explicitly any value it will be set the default value: Always
We'll need to keep in mind that restartPolicy only refers to restarts of the containers by the kubelet on the same node.
If the container keeps failing, the restarts are going to be delayed with an exponential back-off delay: 10s, 20s, 40s, ..., up to five minutes. Once the container has been running for 10 minutes, the kubelet resets the backoff timer for that container
Posted on 01/06/2021