See the following command lines:
NAME READY STATUS RESTARTS AGE stretch-1482165720-qm5bj 0/1 ImagePullBackOff 0 1m stretch-1482165780-bkqjd 0/1 ContainerCreating 0 6s Note that each invocation of a cron job launches a new job object with a new pod: > kubectl get jobs NAME DESIRED SUCCESSFUL AGE stretch-1482165300 1 1 11m stretch-1482165360 1 1 10m stretch-1482165420 1 1 9m stretch-1482165480 1 1 8m
When a cron job invocation completes, its pod gets into a Completed
state and will not be visible without the –show-all
or -a
flags:
> Kubectl get pods --show-all NAME READY STATUS RESTARTS AGE stretch-1482165300-g5ps6 0/1 Completed 0 15m stretch-1482165360-cln08 0/1 Completed 0 14m stretch-1482165420-n8nzd 0/1 Completed 0 13m stretch-1482165480-0jq31 0/1 Completed 0 12m
As usual, you can check the output of the pod of a completed cron job using the logs
command:
> kubectl logs stretch-1482165300-g5ps6 [2016-12-19 16:35:15.325283] Stretch
You must also clean up all the individual jobs, otherwise they will stick around forever. Just deleting the cron job is not enough; it will just stop scheduling more jobs.
You can use the designated label (name=stretch
in this case) to locate all the job objects launched by the cron job.
In summary, the cleanup of a cron job involves the following:
> kubectl delete cronjobs/stretch cronjob "stretch" deleted > kubectl delete jobs -l name=stretch job "stretch-1482165300" deleted job "stretch-1482165360" deleted job "stretch-1482165420" deleted job "stretch-1482165480" deleted
You can also suspend a cron job so it doesn't create more jobs.