Site icon i2tutorials

Kubernetes – Jobs

Kubernetes Jobs

 

Pods are the main purpose of a job, and they ensure that the specified number of pods are successful. When the specified number of pods is successful, the job is considered completed.

Creating a Job

Create a job with this command

apiVersion: v1
kind: Job ------------------------> 1
metadata:
   name: py
   spec:
   template:
      metadata
      name: py -------> 2
      spec:
         containers:
            - name: py ------------------------> 3
            image: python----------> 4
            command: ["python", "SUCCESS"]
            restartPocliy: Never --------> 5

The above code defines −

The job will be created using the following command with yaml and saved as  py.yaml.

$ kubectl create –f py.yaml

You can check the status of a job by running the following command.

$ kubectl describe jobs/py

You can check the status of a job by running the following command.

Scheduled Job

In Kubernetes, scheduled jobs are launched in Kubernetes clusters using Cronetes.

In order to schedule the job, we will use the same YAML we used to create the job.

apiVersion: v1
kind: Job
metadata:
   name: py
spec:
   schedule: h/25 * * * * ? -------------------> 1
   template:
      metadata
         name: py
      spec:
         containers:
         - name: py
         image: python
         args:
/bin/sh -------> 2
-c
ps –eaf ------------> 3
restartPocliy: OnFailure

The above code defines −

The scheduled job concept is useful when we want to run a set of tasks at a specified time and then complete them.

 

Exit mobile version