user8856103
user8856103

Reputation: 53

suspend kubernetes cronjob on job failure to avoid subsequent job runs

Whenever a job run fails I want to suspend cronjob so that no further jobs are started. Is their any possible way? k8s version: 1.10

Upvotes: 3

Views: 3806

Answers (1)

Harsh Manvar
Harsh Manvar

Reputation: 30198

you can configure it simply using suspend: true

apiVersion: batch/v1
kind: Job
metadata:
  name: my-job
spec:
  suspend: true
  parallelism: 2
  completions: 10
  template:
    spec:
      containers:
      - name: my-container
        image: busybox
        command: ["sleep", "5"]
      restartPolicy: Never

Any currently running jobs will complete but future jobs will be suspended.

Read more at : https://kubernetes.io/blog/2021/04/12/introducing-suspended-jobs/

If you are on an older version you can use backoffLimit: 1

apiVersion: batch/v1
kind: Job
metadata:
  name: error
spec:
  backoffLimit: 1
  template:

.spec.backoffLimit can limit the number of time a pod is restarted when running inside a job

If you can't suspend it however we make sure job won't get re-run using

backoffLimit means the number of times it will retry before it is considered failed. The default is 6.

concurrencyPolicy means it will run 0 or 1 times, but not more.

restartPolicy: Never means it won't restart on failure.

Upvotes: 3

Related Questions