Submitting a parallel Job

If your batch Job doesn't have a state or dependency between Jobs, you may consider submitting Jobs in parallel. To do so, similar to the spec.completions parameter, the Job template has a spec.parallelism parameter to specify how many Jobs you want to run in parallel:

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


//submit a parallel job
$ kubectl create -f parallel-job.yaml
job.batch/package-check-parallel created


//check the result
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
package-check-7tfkt 0/1 Completed 0 1h
package-check-parallel-k8hpz 0/1 Completed 0 4s
package-check-parallel-m272g 0/1 Completed 0 4s
package-check-parallel-mc279 0/1 Completed 0 4s
package-check-repeat-flhz9 0/1 Completed 0 13m
package-check-repeat-vl988 0/1 Completed 0 13m
package-check-repeat-xbf8b 0/1 Completed 0 13m

As you see from the AGE column through the kubectl get pods command, it indicates that the three pods ran at the same time.

In this setting, Kubernetes can dispatch to an available node to run your application and that easily scales your Jobs. This is useful if you want to run something like a worker application to distribute a bunch of pods to different nodes.

Lastly, if you no longer need to check the Job's results anymore, delete the resource by using the kubectl delete command as follows:

$ kubectl get jobs
NAME DESIRED SUCCESSFUL AGE
package-check 1 1 1h
package-check-parallel <none> 3 9m
package-check-repeat 3 3 23m


// delete a job one by one
$ kubectl delete jobs package-check-parallel
job.batch "package-check-parallel" deleted

$ kubectl delete jobs package-check-repeat
job.batch "package-check-repeat" deleted

$ kubectl delete jobs package-check
job.batch "package-check" deleted


//there is no pod
$ kubectl get pods
No resources found.
..................Content has been hidden....................

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