Hi everyone! I was trying to create a job setting the property `activeDeadlineSe . . .

Alessandro Borraccino:
Hi everyone! I was trying to create a job setting the property activeDeadlineSeconds: 30 in order to automatically terminate the job after 30sec but it continues to running anyway. What am I missing from here?

  1 apiVersion: batch/v1
  2 kind: Job
  3 metadata:
  4   creationTimestamp: null
  5   name: myjob
  6 spec:
  7   activeDeadlineSeconds: 30
  8   template:
  9     metadata:
 10       creationTimestamp: null
 11     spec:
 12       containers:
 13       - command:
 14         - /bin/sh
 15         - -c
 16         - while true; do echo hello world; sleep 10; done
 17         image: busybox
 18         name: myjob
 19         resources: {}
 20       restartPolicy: Never
 21 status: {}
~                

If I want to check the job I see is running even after 30sec:

controlplane $ k get jobs.batch -w
NAME    COMPLETIONS   DURATION   AGE
myjob   0/1           4m43s      4m43s

Mouhamadou Moustapha Camara:
Hi @Alessandro Borraccino
It’s a normal behaviors
If you did kubectl get pods to check the pods generate by the job you can see that it’s terminated and when you check the job describe k describe job myjob you can see the job is failed with reason DeadlineExceeded.
If you need to clean finished job, you need to use ttlSecondsAfterFinished
Capture d’écran du 2023-01-11 00-24-52.png

Mouhamadou Moustapha Camara:

apiVersion: batch/v1
kind: Job
metadata:
 creationTimestamp: null
 name: myjob
spec:
 activeDeadlineSeconds: 30
 ttlSecondsAfterFinished: 30
 template:
   metadata:
     creationTimestamp: null
   spec:
     containers:
     - command:
       - /bin/sh
       - -c
       - while true; do echo hello world; sleep 10; done
       image: busybox
       name: myjob
       resources: {}
     restartPolicy: Never
status: {}

Mouhamadou Moustapha Camara:
You can see that after 30s the pod is terminated and after 60s (30 + 30) the job is deleted

Alessandro Borraccino:
thanks! very great clarification :smile: