I defined a test job:
apiVersion: batch/v1
kind: Job
metadata:
name: testjob
spec:
activeDeadlineSeconds: 100
backoffLimit: 3
template:
spec:
containers:
- name: testjob
image: bitnami/kubectl:1.20
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- echo "Test" && exit 1
restartPolicy: Never
All of the pods failed "properly", but the duration counter of the job won't stop.
$ kubectl get pods,jobs
NAME READY STATUS RESTARTS AGE
pod/testjob-s2cbf 0/1 Error 0 3m15s
pod/testjob-nhfgn 0/1 Error 0 3m14s
pod/testjob-8jw74 0/1 Error 0 3m4s
pod/testjob-jh7hl 0/1 Error 0 2m24s
NAME COMPLETIONS DURATION AGE
job.batch/testjob 0/1 3m15s 3m15s
$ kubectl describe job testjob
Name: testjob
Namespace: default
Selector: controller-uid=8a1f31c7-8d9d-4b4d-a687-e8e297509a71
Labels: controller-uid=8a1f31c7-8d9d-4b4d-a687-e8e297509a71
job-name=testjob
Annotations: <none>
Parallelism: 1
Completions: 1
Start Time: Wed, 17 Mar 2021 18:13:56 +0000
Active Deadline Seconds: 100s
Pods Statuses: 0 Running / 0 Succeeded / 4 Failed
Pod Template:
Labels: controller-uid=8a1f31c7-8d9d-4b4d-a687-e8e297509a71
job-name=testjob
Containers:
testjob:
Image: bitnami/kubectl:1.20
Port: <none>
Host Port: <none>
Command:
/bin/sh
-c
echo "Test" && exit 1
Environment: <none>
Mounts: <none>
Volumes: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 4m11s job-controller Created pod: testjob-s2cbf
Normal SuccessfulCreate 4m10s job-controller Created pod: testjob-nhfgn
Normal SuccessfulCreate 4m job-controller Created pod: testjob-8jw74
Normal SuccessfulCreate 3m20s job-controller Created pod: testjob-jh7hl
Warning BackoffLimitExceeded 2m job-controller Job has reached the specified backoff limit
However, if one the pods finish successfully (status: completed) the duration counter stops as expected.
What is the problem here?