In AKS, the restart policy defines how Kubernetes restarts containers inside a Pod when they exit (fail or stop).
Restart Policy is Defined at the Pod Level
It’s set in the Pod spec under .spec.restartPolicy.
There are 3 types:
| Restart Policy | Description |
|---|---|
Always | Always restarts the container if it fails (default for regular Pods). Default for Deployments, ReplicaSets, etc. |
OnFailure | Restarts only if the container exits with a non-zero status (i.e., error). |
Never | Never restarts the container, even if it fails. |
Example
apiVersion: v1
kind: Pod
metadata:
name: sample-pod
spec:
containers:
name: myapp
image: nginx
restartPolicy: Always
Where is it Used?
- In regular Pods: default is
Always. - In Jobs: typically uses
OnFailureorNever. - In DaemonSets, Deployments, ReplicaSets: enforced to use
Always(Kubernetes will reject any other).
In Layman’s Terms:
- Imagine your app crashes – should Kubernetes try to restart it?
- Yes, always? → use
Always - Only if it crashes with an error? → use
OnFailure - Let it die and don’t touch it? → use
Never
- Yes, always? → use

Leave a Reply