Menu

Dipesh Majumdar

Blog and Paintings

activeDeadlineSeconds and backoffLimit

Lets create a job - 

apiVersion: batch/v1
kind: Job
metadata:
  creationTimestamp: null
  labels:
    run: shuffle-job
  name: shuffle-job
spec:
  backoffLimit: 40
  activeDeadlineSeconds: 120
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: shuffle-job
    spec:
      containers:
      - args:
        - /bin/sh
        - -c
        - while true; do i=$(shuf -i 1-100 -n 1); if [ $i -gt 90 ];then echo success;
          exit 0; else echo failure; exit 1; fi; done;
        image: busybox
        name: shuffle-job
        resources: {}
      restartPolicy: Never
status: {}

The above job exits with 0 and thus deemed successful only if the random number generated is greater than 90. We allow the job to fail only if no. of attempts exceeds backoffLimit or activeDeadlineSeconds. activeDeadlineSeconds always takes precedence over backoffLimit.

Here is sample output of a describe job - 

Active Deadline Seconds:  120s
Pods Statuses:            0 Running / 0 Succeeded / 5 Failed
Pod Template:
  Labels:  controller-uid=32760c17-6403-11e9-a71d-42010a8400e1
           job-name=shuffle-job
           run=shuffle-job
  Containers:
   shuffle-job:
    Image:      busybox
    Port:       <none>
    Host Port:  <none>
    Args:
      /bin/sh
      -c
      while true; do i=$(shuf -i 1-100 -n 1); if [ $i -gt 90 ];then echo success; exit 0; else echo failure; exit 1; fi; done;
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type     Reason            Age    From            Message
  ----     ------            ----   ----            -------
  Normal   SuccessfulCreate  14m    job-controller  Created pod: shuffle-job-r4mst
  Normal   SuccessfulCreate  14m    job-controller  Created pod: shuffle-job-wp6rz
  Normal   SuccessfulCreate  14m    job-controller  Created pod: shuffle-job-gswlc
  Normal   SuccessfulCreate  13m    job-controller  Created pod: shuffle-job-p8rts
  Normal   SuccessfulCreate  12m    job-controller  Created pod: shuffle-job-x6sxq
  Warning  DeadlineExceeded  7m19s  job-controller  Job was active longer than specified deadline

 

 

 

Go Back

Comment