Kubernetes restart policies
What's inside this article
⌄
- Kubernetes restart policy types
- K8s container recovery options
- Kubernetes pod restart configuration
- K8s high availability setup
There are several types of workloads in general, including:
- Long-running apps like web servers
- Short-lived apps like batch jobs
Suppose you have a web server, and it just crashed for some reason. It takes time to:
- Figure out that your service is actually down
- Log in to your cluster and restart a pod.
Therefore, it’s better to make use of a right restart policy in k8s.
The restart policy for a container is defined within the context of a pod, which is the smallest deployable unit in the Kubernetes architecture. It determines the conditions under which a container should be restarted within a pod.
There are three main restart policies:
- Always. It will restart the container indefinitely, regardless of the exit status.
- OnFailure. The container will be restarted only if it exits with a non-zero status.
- Never. No restarts at all.
The default one is Always.
You can set the value under the corresponding property in your deployment.yaml:
apiVersion: v1
kind: Pod
metadata:
name: example-pod
spec:
restartPolicy: Never
containers:
- name: my-container
image: my-image:latest
In the previous article, we figured out how to install k8s on the desktop.
Try it yourself!