Jobs

You might also need to run large computation or batch processing workloads in your clusters. For this, Job controller is useful.

A job creates one or more pods running in parallel. You can specify how many number of pods need to complete in this Job. When a specified number of pods successfully completed, the job itself is complete.

If the first pod fails or is deleted, the Job controller will start a new Pod.

The job is designed for parallel processing of independent but related work items like sending emails, rendering frames, transcoding files, scanning database keys, etc.

Here is the configuration for Job manifest

apiVersion: batch/v1
kind: Job
metadata:
  name: example-job
spec:
  template:
    metadata:
      name: example-job
    spec:
      containers:
      - name: pi
        image: perl
        command: ["perl"]
        args: ["-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never

Create the Job

$ kubectl apply -f example-job.yaml 
job.batch "example-job" created
$ kubectl get jobs
NAME          DESIRED   SUCCESSFUL   AGE
example-job   1         0            33s
$ kubectl get pods
NAME                READY     STATUS              RESTARTS   AGE
example-job-pzxhn   0/1       ContainerCreating   0          23s
$ kubectl get pods
NAME                READY     STATUS      RESTARTS   AGE
example-job-pzxhn   0/1       Completed   0          51s
$ kubectl get jobs
NAME          DESIRED   SUCCESSFUL   AGE
example-job   1         1            1m

 

Click here to read more about jobs

Advertisements