Create a repeatable Job

Users can also decide the number of tasks that should be finished in a single Job. It is helpful to solve some random and sampling problems. Let's try it on the same template in the previous example:

  1. Add the spec.completions item to indicate the Pod number:
$ cat job-dpkg-repeat.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: package-check
spec:
completions: 3
template:
spec:
containers:
- name: package-check
image: ubuntu
command: ["dpkg-query", "-l"]
restartPolicy: Never
  1. After creating this Job, check how the Pod looks with the subcommand kubectl describe:
$ kubectl create -f job-dpkg-repeat.yaml 
job.batch "package-check" created

$ kubectl describe jobs package-check
Name: package-check
Namespace: default
...
...
Annotations: <none>
Parallelism: 1
Completions: 3
Start Time: Tue, 09 Jan 2018 22:58:09 -0800
Pods Statuses: 0 Running / 3 Succeeded / 0 Failed
...
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 42s job-controller Created pod: package-check-f72wk
Normal SuccessfulCreate 32s job-controller Created pod: package-check-2mnw8
Normal SuccessfulCreate 27s job-controller Created pod: package-check-whbr6

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 preceding result, these Pods ran sequentially, one by one. This means that the 2nd Job was started after the 1st Job was completed, and the 3rd Job was started after the 2nd Job was completed.

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

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