What is Restart Policy in AKS (Azure Kubernetes Service)?

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 PolicyDescription
AlwaysAlways restarts the container if it fails (default for regular Pods).
OnFailureRestarts only if the container exits with a non-zero status (i.e., error).
NeverNever 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 OnFailure or Never.
  • 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

Leave a Comment

Your email address will not be published. Required fields are marked *