Submitting a repeatable Job

Users can also decide the number of tasks that should be finished in a single Job. This is helpful for solving some random sampling problems. Let's reuse the previous template and add spec.completions to see the differences:

$ cat repeat-job.yaml 
apiVersion: batch/v1
kind: Job
metadata:
name: package-check-repeat
spec:
activeDeadlineSeconds: 60
completions: 3
template:
spec:
containers:
- name: package-check-repeat
image: ubuntu
command: ["dpkg-query", "-l"]
restartPolicy: Never


$ kubectl create -f repeat-job.yaml
job.batch/package-check-repeat created


$ kubectl get pods
NAME READY STATUS RESTARTS AGE
package-check-7tfkt 0/1 Completed 0 52m
package-check-repeat-vl988 0/1 Completed 0 7s
package-check-repeat-flhz9 0/1 Completed 0 4s
package-check-repeat-xbf8b 0/1 Completed 0 2s

As you can see, three pods are created to complete this Job. This is useful if you need to run your program repeatedly at particular times. However, as you may have noticed from the Age column in the preceding result, these pods ran sequentially one by one. In the preceding result, the ages are 7 seconds, 4 seconds, then 2 seconds. This means that the second Job was started after the first Job was completed, and the third Job was started after the second Job was completed.

If it is the case that a Job runs for a longer period (such as a few days), but if there is no correlation needs between the 1st, 2nd, and 3rd Job, then it does not make sense to run them sequentially. In this case, use a parallel Job.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset