What is a use case for kubernetes job?

6/26/2017

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.

-- Jxadro
kubernetes
kubernetes-jobs

2 Answers

1/3/2018

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
Source: StackOverflow

6/27/2017

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
Source: StackOverflow