Let’s take the following Kubernetes Cronjob
apiVersion: batch/v1
kind: CronJob
metadata:
name: sleep-cronjob
spec:
schedule: "*/5 * * * *"
jobTemplate:
spec:
backoffLimit: 0 # Avoid two executions
template:
spec:
containers:
- name: sleep
image: busybox
command: ["sh", "-c", "sleep 120"] # 2 minutes
restartPolicy: Never
terminationGracePeriodSeconds: 300 # 5 minutes
It runs a job every 5 minutes, and the pod sleeps for 2 minutes.
If during the sleep I execute the kubectl delete pod <POD_NAME>
for a graceful termination, it will work, it will wait for the specified terminationGracePeriodSeconds
and in this case, it will allow the pod to finish its job successfully.
But, the Kubernetes Job will be marked as 1 Failed
with the reason BackoffLimitExceeded
.
I have tried the Job configuration activeDeadlineSeconds and I’m still getting the error.
Am I missing a configuration or something for the CronJob/Job to prevent this?