Pre-requisite: Kubernetes
In the Kubernetes world, jobs are considered an object to act as a supervisor or controllers of a task. The Kubernetes job will create a pod, monitor the task, and recreate another one if that pod fails for some reason. Upon completion of the task, it will terminate the pod. Unlike deployment and pods, you can specify a job in Kubernetes which can be an always one job or time-based job, or a task-based job. This allows you to tolerate error or failure which can cause unexpected pods termination.
When you submit a job it will create one or more pods based on the requirement, will complete the task defined in the job, and keep the pods running until the task is completed. The Job keeps track of the successful completions when pods finish up. When a job is suspended, all of its active Pods are deleted until the job is restarted.
Job Types:
- Non-Parallel Job: A simple job where a single task is defined and which will create one pod and upon successful completion of the job the pod will terminate.
- Parallel Job with fixed completion count: A complex task is defined as a job that requires multiple pods to complete the task which can run in parallel and each Pod receives a unique index between 0 and.spec.completions-1 based on the number specified in config `.spec.completions`. The job will be considered completed successfully when there is a successful spec. completions Pods.
- Parallel Job with a work queue: In parallel jobs with a work queue, multiple pods are running in parallel to complete complex data with decencies. To decide what each Pod should focus on, the Pods will need to cooperate with one another or with an outside service. For instance, a Pod might pull up to N items in a batch from the work queue. Each Pod is capable of autonomously determining whether or not all of its peers are finished, and hence if the entire Job is finished.
Use Cases:
- A simple use case for a job to perform some system operations task. For example to set up a cluster or service you need to perform some tasks in multiple places. You can create a job and use that, again and again, to bring up the same service or perform a similar task.
- Another use case is performing some data backups or some computation tasks. A more complex use case can be a series of task which needs to be performed in order where jobs will be created pods and managed until the no of completions is met. As part of establishing services, Helm Charts employ Jobs to conduct install, set up, or test commands on clusters.
Key Terminologies:
There are a few key terminologies we are using throughout the article.
- Kubernetes: Kubernetes is an open-source system, from Google for orchestrating containers. Allow automation of most of the operational tasks around containerized applications.
- Pods: The smallest deployable compute units that Kubernetes allows you to construct and control are called pods. It can be a single container or a combination of containers.
- Minikube: A local version of Kubernetes to get you started and testing your work locally.
Steps To Setup Job:
Today, we will consider an example of setting up a job that will use Docker Busybox image and ping geeksforgeeks.org.
Step 1. Start your minikube
$ minikube start
Step 2. Create the job definition file in YAML format.
$ cat ping-job.yaml
Step 3. Submit the job definition to Kubectl, you should see the job created message on execution.
$ kubectl apply -f ping-job.yaml
Step 4. List the job using get jobs, we can see the no of completion of our job as well as the duration and age.
$ kubectl get jobs
Step 5. Get the job details.
$ kubectl describe job ping
Step 6. Get the pods running for our jobs, here you can see the pod name, how many containers, its status, whether its restarted or not, and the age of the pod.
$ kubectl get pods
You can check the logs of the container.
To delete the job use kubectl delete command, If you delete the job, the pods associated with it will be deleted as well.
$ kubectl delete job ping
$kubectl get job
Similar Reads
DevOps Tutorial DevOps is a combination of two words: "Development" and "Operations." Itâs a modern approach where software developers and software operations teams work together throughout the entire software life cycle, from planning and coding to testing, deploying, and monitoring.The main idea of DevOps is to i
9 min read
Introduction
What is DevOps ?DevOps is a modern way of working in software development in which the development team (who writes the code and builds the software) and the operations team (which sets up, runs, and manages the software) work together as a single team.Before DevOps, the development and operations teams worked sepa
10 min read
DevOps LifecycleThe DevOps lifecycle is a structured approach that integrates development (Dev) and operations (Ops) teams to streamline software delivery. It focuses on collaboration, automation, and continuous feedback across key phases planning, coding, building, testing, releasing, deploying, operating, and mon
10 min read
The Evolution of DevOps - 3 Major Trends for FutureDevOps is a software engineering culture and practice that aims to unify software development and operations. It is an approach to software development that emphasizes collaboration, communication, and integration between software developers and IT operations. DevOps has come a long way since its in
7 min read
Version Control
Continuous Integration (CI) & Continuous Deployment (CD)
Containerization
Orchestration
Infrastructure as Code (IaC)
Monitoring and Logging
Microsoft Teams vs Slack Both Microsoft Teams and Slack are the communication channels used by organizations to communicate with their employees. Microsoft Teams was developed in 2017 whereas Slack was created in 2013. Microsoft Teams is mainly used in large organizations and is integrated with Office 365 enhancing the feat
4 min read
Security in DevOps