restart policy in Kubernetes deployment

2/9/2022

Is it possible to create a deployment on Kubernetes and using restart policy on failure ? I did a small research but didn't find anything that enables restart policy on failure for Deployment.

KR

-- Wassim Ben Salem
kubernetes

1 Answer

2/9/2022

restartPolicy for kind: Deployment support Always only.

One of the requirements is "restart policy on failure max 3 times"

Try:

apiVersion: batch/v1
kind: Job
metadata:
  name: busybox
spec:
  template:
    backoffLimit: 3  # <-- max fail 3 times
    spec:
      restartPolicy: OnFailure  # <-- You can do this with job
      containers:
      - name: busybox
        image: busybox
        command: ["ash","-c","sleep 15"]  # <-- replace with an invalid command to see backoffLimit in action
-- gohm&#39;c
Source: StackOverflow