Cron jobs can leave behind artifact resources such as jobs or pods. Configuring history limits is important, so that old jobs and their pods are properly cleaned. There are
two optional fields within cron job’s spec responsible for that:
apiVersion: batch/v2alpha1
kind: CronJob
metadata:
name: pi
spec:
successfulJobsHistoryLimit: 3 (1)
failedJobsHistoryLimit: 1 (2)
schedule: "*/1 * * * *"
jobTemplate:
spec:
...
1 |
The number of successful finished jobs to retain. |
2 |
The number of failed finished jobs to retain. |
At any point in time, you can manually verify all artifacts left over from a job execution by using
the job name as their prefix. For example, given the cron job example:
$ oc get jobs
NAME DESIRED SUCCESSFUL AGE
pi-1497848100 1 1 1m
pi-1497848160 1 1 49s
$ oc get pods
NAME READY STATUS RESTARTS AGE
pi-1497848100-lxs4k 0/1 Completed 0 2m
pi-1497848160-6r0c8 0/1 Completed 0 59s
Delete each artifact if you no longer need them. To delete all jobs spawned by a cron job, specify the label set during cron job creation:
$ oc delete jobs -l <label>
For example, to delete only the jobs generated by the cron job example:
$ oc delete jobs -l parent=cronjobpi
job "pi-1497848100" deleted
job "pi-1497848160" deleted