Pages

Tuesday, August 7, 2018

Kubernetes - Parallelism in Jobs

If the job does not have any dependency between them, we can have the job run in parallel. Lets create a job that lets the pods run in parallel,

[root@manja17-I13330 kubenetes-config]# cat basic-parallelism-job.yml
apiVersion: batch/v1
kind: Job
metadata:
  name: testing-service
spec:
  parallelism: 3
  template:
    metadata:
      labels:
        name: testing-service
    spec:
      containers:
      - name: counter
        image: centos:7
        command:
          - "bin/bash"
          - "-c"
          - "for i in 9 8 7 6 5 4 3 2 1 ; do echo $i ; done"
      restartPolicy: Never

[root@manja17-I13330 kubenetes-config]# kubectl create -f basic-parallelism-job.yml
job.batch "testing-service" created

[root@manja17-I13330 kubenetes-config]# kubectl get jobs
NAME                DESIRED   SUCCESSFUL   AGE
testing-service   <none>     2                    4s

[root@manja17-I13330 kubenetes-config]# kubectl get pods
NAME                        READY     STATUS      RESTARTS   AGE
testing-service-4jq5r   0/1       Completed    0                7s
testing-service-ltlq4    0/1       Completed    0                7s
testing-service-vjn2w  0/1       Completed    0                7s

Describe the job using,
[root@manja17-I13330 kubenetes-config]# kubectl describe job testing-service
Name:           testing-service
Namespace:      default
Selector:       controller-uid=3eb65bba-8f0d-11e8-a791-020055e1ea1d
Labels:         controller-uid=3eb65bba-8f0d-11e8-a791-020055e1ea1d
                job-name=testing-service
                name=testing-service
Annotations:    <none>
Parallelism:    3
Completions:    <unset>
Start Time:     Tue, 24 Jul 2018 02:46:08 -0400
Pods Statuses:  0 Running / 3 Succeeded / 0 Failed
Pod Template:
  Labels:  controller-uid=3eb65bba-8f0d-11e8-a791-020055e1ea1d
           job-name=testing-service
           name=testing-service
  Containers:
   counter:
    Image:      centos:7
    Port:       <none>
    Host Port:  <none>
    Command:
      bin/bash
      -c
      for i in 9 8 7 6 5 4 3 2 1 ; do echo $i ; done
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From            Message
  ----    ------            ----  ----            -------
  Normal  SuccessfulCreate  15s   job-controller  Created pod: testing-service-vjn2w
  Normal  SuccessfulCreate  15s   job-controller  Created pod: testing-service-4jq5r
  Normal  SuccessfulCreate  15s   job-controller  Created pod: testing-service-ltlq4

No comments :

Post a Comment