Create a parallel Job

If your batch Job doesn't have a state or dependency between Jobs, you may consider submitting Jobs in parallel. 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:

1. Re-use a repeatable Job but change it to specify spec.parallelism: 3 as follows:

$ cat job-dpkg-parallel.yaml 
apiVersion: batch/v1
kind: Job
metadata:
name: package-check
spec:
parallelism: 3
template:
spec:
containers:
- name: package-check
image: ubuntu
command: ["dpkg-query", "-l"]
restartPolicy: Never
  1. The result is similar to spec.completions=3, which made 3 Pods to run your application:
$ kubectl get pods --show-all
NAME READY STATUS RESTARTS AGE
package-check-5jhr8 0/1 Completed 0 1m
package-check-5zlmx 0/1 Completed 0 1m
package-check-glkpc 0/1 Completed 0 1m
  1. However, if you see an Age column through the kubectl describe command, it indicates that 3 Pods ran at the same time:
$ kubectl describe jobs package-check
Name: package-check
Namespace: default
Selector: controller-uid=de41164e-f5d6-11e7-8233-ae782244bd54
Labels: controller-uid=de41164e-f5d6-11e7-8233-ae782244bd54
job-name=package-check
Annotations: <none>
Parallelism: 3
Completions: <unset>

Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 24s job-controller Created pod: package-check-5jhr8
Normal SuccessfulCreate 24s job-controller Created pod: package-check-glkpc
Normal SuccessfulCreate 24s job-controller Created pod: package-check-5zlmx

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

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

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