CronJob In Kubernetes

Introduction

CronJobSpec API fields

Example:

Example:

API field for CronJobStatus

root@vagrant:/home/vagrant# kubectl apply -f https://gist.githubusercontent.com/spy86/9be6bcce55be75a55a319e563954389d/raw/ae07f8acd7b1a83097e780be2226f7d4bd4d06eb/test-cronjob.yml
cronjob.batch/example-cronjob created
root@vagrant:/home/vagrant# kubectl get cronjobs
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
example-cronjob */1 * * * * False 0 <none> 46s
root@vagrant:/home/vagrant# kubectl get jobs
NAME COMPLETIONS DURATION AGE
example-cronjob-1618510560 1/1 3s 4m19s
example-cronjob-1618510620 1/1 3s 3m19s
example-cronjob-1618510680 1/1 3s 2m18s
example-cronjob-1618510740 1/1 3s 78s
example-cronjob-1618510800 1/1 3s 17s
root@vagrant:/home/vagrant# kubectl get po
NAME READY STATUS RESTARTS AGE
example-cronjob-1618510680-bkhgq 0/1 Completed 0 4m33s
example-cronjob-1618510740-czsg2 0/1 Completed 0 3m33s
example-cronjob-1618510800-jn4nj 0/1 Completed 0 2m32s
example-cronjob-1618510860-62rkf 0/1 Completed 0 92s
example-cronjob-1618510920-v4rtm 0/1 Completed 0 31s

Stop/Suspend our CronJobs

root@vagrant:/home/vagrant# kubectl get cronjobs
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
example-cronjob */1 * * * * False 0 47s 10m
root@vagrant:/home/vagrant# kubectl patch cronjob example-cronjob -p'{"spec": {"suspend": true}}'
cronjob.batch/example-cronjob patched
root@vagrant:/home/vagrant# kubectl get cronjob
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
example-cronjob */1 * * * * True 0 70s 11m
root@vagrant:/home/vagrant#
Source:https://giphy.com/

DevOps Consultant. I’m strongly focused on automation, security, and reliability.