Kubernetes - Jobs
Kubernetes jobs
In Kubernetes, A job is use to execute a finite task. Some examples are sending emails, transcoding files, scanning database keys, etc.
Job
job.yaml - a sample job
1 | apiVersion: batch/v1 |
Jobs are executed using kubectl apply
command
1 | kubectl apply -f job.yaml |
use kubectl get pod
command to get the pod name and then use kubectl logs
command to see the output.
1 | $ kubectl get pod |
use kubectl delete cron hellojob
to delete the job.
Parallel Jobs
The above job execute only once. You can have the job execute multiple times in parallel.
1 | apiVersion: batch/v1 |
Here the job is execute 3 times with 2 pods executing in parallel.
We can examine the jobs that is completed.
1 | $ kubectl get jobs |
use kubectl delete cron hellojob
to delete the job.
CronJob
CronJob runs on a schedule.
1 | apiVersion: batch/v1beta1 |
A pod is spin up to run the cronjob every minute.
Use kubectl get cronjobs
command to see the cronjob
1 | $ kubectl get cronjobs |
use kubectl delete cronjob hellojob
to delete the cronjob.