How to ensure kubernetes cronjob does not restart on failure
It turns out that you have to set a backoffLimit: 0
in combination with restartPolicy: Never
in combination with concurrencyPolicy: Forbid
.
backoffLimit means the number of times it will retry before it is considered failed. The default is 6.
concurrencyPolicy set to Forbid
means it will run 0 or 1 times, but not more.
restartPolicy set to Never
means it won't restart on failure.
You need to do all 3 of these things, or your cronjob may run more than once.
spec:
concurrencyPolicy: Forbid
failedJobsHistoryLimit: 1
jobTemplate:
metadata:
creationTimestamp: null
spec:
[ADD THIS -->]backoffLimit: 0
template:
... MORE STUFF ...