3

I'm looking to fully understand the jobs in kubernetes.

I have successfully create and executed a job, but I do not see the use case.

Not being able to rerun a job or not being able to actively listen to it completion makes me think it is a bit difficult to manage.

Anyone using them? Which is the use case?

Thank you.

Eyal Levin
  • 16,271
  • 6
  • 66
  • 56
Jxadro
  • 1,497
  • 2
  • 16
  • 36

2 Answers2

3

A job retries pods until they complete, so that you can tolerate errors that cause pods to be deleted.

If you want to run a job repeatedly and periodically, you can use CronJob alpha or cronetes.

Some Helm Charts use Jobs to run install, setup, or test commands on clusters, as part of installing services. (Example).

If you save the YAML for the job then you can re-run it by deleting the old job an creating it again, or by editing the YAML to change the name (or use e.g. sed in a script).

You can watch a job's status with this command:

kubectl get jobs myjob -w

The -w option watches for changes. You are looking for the SUCCESSFUL column to show 1.

Here is a shell command loop to wait for job completion (e.g. in a script): until kubectl get jobs myjob -o jsonpath='{.status.conditions[?(@.type=="Complete")].status}' | grep True ; do sleep 1 ; done

Eric Tune
  • 7,819
  • 1
  • 15
  • 17
  • in k8s documentation they have given example of task distribution for parallel processing https://kubernetes.io/docs/tasks/job/fine-parallel-processing-work-queue/ . I am intrigued does people uses it for such type of work on production env with job? – Thinker Aug 29 '23 at 20:40
  • Like i can think of a use case where i have deployed let's say my kafka consumers as a pod but not via job, normal deployment. they are just running. And new pods can be created when lets say memory or cpu consumption exceed. – Thinker Aug 29 '23 at 20:42
1

One of the use case can be to take a backup of a DB. But as already mentioned that are some overheads to run a job e.g. When a Job completes the Pods are not deleted . so you need to manually delete the job(which will also delete the pods created by job). so recommended option will be to use Cron instead of Jobs

Rajeev Ghosh
  • 121
  • 10