Jobs

1. Introduction

A job is a supervisor for pods carrying out batch processes, that is, a process that runs for a certain time to completion, for example a calculation or a backup operation.

2. An example

Let's create a job called countdown

kubectl create -f https://raw.githubusercontent.com/mhausenblas/kbe/master/specs/jobs/job.yaml
hadoop@k8s-00:~$ kubectl create -f https://raw.githubusercontent.com/mhausenblas/kbe/master/specs/jobs/job.yaml
job.batch "countdown" created
  • get the job as follows
hadoop@k8s-00:~$ kubectl get jobs
NAME        DESIRED   SUCCESSFUL   AGE
countdown   1         1            33s
  • get the pods
hadoop@k8s-00:~$ kubectl get pods
NAME              READY     STATUS      RESTARTS   AGE
countdown-l9wzj   0/1       Completed   0          59s
  • get more about the status of the job using
hadoop@k8s-00:~$ kubectl describe jobs/countdown
Name:           countdown
Namespace:      default
Selector:       controller-uid=d972ad70-72b3-11e8-9751-76fd51353592
Labels:         controller-uid=d972ad70-72b3-11e8-9751-76fd51353592
                job-name=countdown
Annotations:    <none>
Parallelism:    1
Completions:    1
Start Time:     Mon, 18 Jun 2018 04:55:40 +0000
Pods Statuses:  0 Running / 1 Succeeded / 0 Failed
Pod Template:
  Labels:  controller-uid=d972ad70-72b3-11e8-9751-76fd51353592
           job-name=countdown
  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  1m    job-controller  Created pod: countdown-l9wzj
  • to see output of the job use
hadoop@k8s-00:~$ kubectl get pods
NAME              READY     STATUS      RESTARTS   AGE
countdown-l9wzj   0/1       Completed   0          2m
hadoop@k8s-00:~$ kubectl logs countdown-l9wzj
9
8
7
6
5
4
3
2
1
  • delete the job using delete keyword
hadoop@k8s-00:~$ kubectl delete job countdown
job.batch "countdown" deleted

results matching ""

    No results matching ""