The Wayback Machine - https://web.archive.org/web/20241009144052/https://www.geeksforgeeks.org/kubernetes-jobs/
Open In App

Kubernetes – Jobs

Last Updated : 30 Mar, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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:

  1. 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. 
  2. 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.
  3. 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:

  1. 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. 
  2. 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. 

  1. Kubernetes: Kubernetes is an open-source system, from Google for orchestrating containers. Allow automation of most of the operational tasks around containerized applications. 
  2. 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. 
  3. 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
minikube start

 

Step 2. Create the job definition file in YAML format. 

$ cat ping-job.yaml
Job Definition file in YAML format

 

Step 3. Submit the job definition to Kubectl, you should see the job created message on execution. 

 $ kubectl apply -f ping-job.yaml
Submit the job to Kubernetes

 

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
Get job

 

Step 5. Get the job details.

$ kubectl describe job ping 
Describe the job

 

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
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
Delete Job

 


Previous Article
Next Article

Similar Reads

Kubernetes - Monolithic Architecture of Kubernetes
There is a new way of developing software apps using a microservices architecture. That's when all the buzz around containers and container orchestration has increased but we have been developing and using these large software apps even before most of us were born. So in this article, we will be discussing what is that old software architecture we
7 min read
Why Kubernetes? Benefits of using Kubernetes
The popularity of container orchestration technologies specially Kubernetes comes from its use cases and the problems that it solves. Kubernetes is the most popular container orchestration and is widely used by Cloud Native Computing Foundation (CNCF), the foundation to which Kubernetes as a project was donated by Google, estimates that about 92% b
8 min read
Kubernetes Controller VS Kubernetes Operator
Kubernetes Controllers are ideal for managing stateless apps and maintaining the correct number of copies, but Kubernetes Operators are more appropriate for complicated, stateful applications that require human-like decision-making abilities. Kubernetes ControllerKubernetes Controllers are ideal for managing stateless apps and maintaining the corre
4 min read
Kubernetes Jobs and CronJobs for Scheduled Tasks
Kubernetes is a platform, that is used to manage the application in containerized form. It offers specific resources to execute the batch jobs and recurring tasks on a time or a Time Interval basis. In this post, I am gonna show you the 2 main features Kubernetes Jobs and Cron Jobs, to effectively task scheduling within a Kubernetes cluster. Table
6 min read
How Raspberry Pi and Kubernetes Work Together?
Pre-requisite: Kubernetes and Raspberry Pi Kubernetes and Raspberry Pi are two popular technologies that can be used together to create powerful and scalable applications. In this article, we will look at what each technology is, how they work together, and the benefits and challenges of using the two technologies together. KubernetesKubernetes is
3 min read
Kubernetes - Introduction to Container Orchestration
In this article, we will look into Container Orchestration in Kubernetes. But first, let's explore the trends that gave rise to containers, the need for container orchestration, and how that it has created the space for Kubernetes to rise to dominance and growth. The growth of technology into every aspect of our lives and days has created immense d
4 min read
Kubernetes - Autoscaling
Pre-requisite: Kubernetes Life before Kubernetes is like writing our code and pushing the code into physical servers in a data center and managing the resources needed by that server to run our application smoothly and another type is deploying our code in virtual machines(VM). With VMs also have problems with hardware and software components requi
8 min read
Kubernetes - Physical Servers vs Virtual Machines vs Containers
Kubernetes is an open-source framework for managing containerized workloads and services that allows declarative configuration as well as automation. It has a huge and fast-expanding ecosystem. Services, support, and tools for Kubernetes are widely available. Kubernetes is a Greek word that means "helmsman" or "pilot." The acronym K8s comes from co
3 min read
Kubernetes - Taint and Toleration
A pod is a group of one or more containers and is the smallest deployable unit in Kubernetes. A node is a representation of a single machine in a cluster (we can simply view these machines as a set of CPU and RAM). A node can be a virtual machine, a physical machine in a data center hosted on a cloud provider like Azure. When a user runs the below-
6 min read
How to Enable JMX For Java Application Running in the Kubernetes Cluster?
Many times we want to monitor our application's CPU utilization, background thread behavior, and most importantly memory consumptions for tasks that deal with loads for data (500MB - 1GB) or much more data. Such monitoring helps to find which operation is causing heavy CPU or Memory utilization and helps to find the reason behind Memory leak issues
3 min read
Enable Remote Debugging For Java Application Deployed in Kubernetes Environment
During Development, developers have to debug their applications to resolve code problems. In order to debug a java application which is deployed on remote machine in a Kubernetes cluster, first developer has to do some steps to enable its application ready for debugging. Below are the manual steps to enable remote debugging for any java application
2 min read
Kubernetes - Working With Secrets
Kubernetes Secrets are objects that are used to store secret data in base64 encoded format. Using secrets enables developers not to put confidential information in the application code. Since Secrets are created independently of the pods, there is less risk of secrets being exposed. Uses of Secrets: As files in a volume mounted on one or more of it
1 min read
Kubernetes Resource Model (KRM) and How to Make Use of YAML?
Here we will explain how YAML can simplify system management and automation of most processes so that Kubernetes is a convenient working system. Basic Kubernetes Models: KRM and Everything-as-CodeAccording to Kubernetes co-founder Brian Grant, Kubernetes is very convenient thanks to the Kubernetes Resource Model (KRM) resource model. This is a way
6 min read
Kubernetes Policies
Pre-requisite: Kubernetes In this article, we will be discussing Kubernetes policies, a key feature in the Kubernetes platform that allows administrators to enforce rules and restrictions on the use and management of resources within a cluster. We will cover the basics of Kubernetes policies, including their types and how they are implemented and m
4 min read
Kubernetes - Create ConfigMap From YAML File
A ConfigMap is a dictionary consisting of non-confidential data. Its primary role is to keep the configuration separate from the container image. ConfigMap can be created in different ways. This article will cover the declarative approach to creating ConfigMap from the YAML file. Example: apiVersion: This specifies which version of Kubernetes API w
1 min read
Kubernetes - Create Config Map From Files
Pre-requisite: Kubernetes While creating a manifest file in Kubernetes, we can define environment variables. However, when you have a lot of manifest files, it will become difficult to manage the environment data stored in various manifest files. To overcome this issue, we can manage environment data centrally using ConfigMaps. ConfigMaps are used
2 min read
Kubernetes - Creating Multiple Container in a Pod
Pre-requisite:- Kubernetes Kubernetes is a container management tool and it automates container deployment, load balancing, and container scaling. It is open-source and developed by Google in 2014 and written in Golang. All cloud providers adopt Kubernetes. It is scheduled runs and manages isolated containers that are running on virtual, physical,
3 min read
Kubernetes - Images
Pre-requisite:- Kubernetes A container image is used to represent binary data that is being used to encapsulate an application and all its software dependencies. Container images can be represented as executable software bundles that run standalone and make very defined assumptions about their runtime environment. Generally, we create a container i
3 min read
Kubernetes - Injecting ConfigMap as Files
Pre-requisite:- Kubernetes The automated deployment, scaling, and administration of software using a system called Kubernetes, an open-source container orchestration tool. K8s is another name for Kubernetes. Kubernetes was initially developed by Google and is now managed by the Cloud Native Computing Foundation. Despite the fact that it now support
3 min read
Kubernetes - Config Map From Directory
Pre-requisite:- Kubernetes Software deployment, scalability, and administration are mostly automated using Kubernetes, an open-source container orchestration framework. K8s is another name for Kubernetes. Kubernetes was initially developed by Google and is now managed by the Cloud Native Computing Foundation. Despite the fact that it now supports C
2 min read
Kubernetes - Services
Software deployment, scaling, and management are all automated using Kubernetes, an open-source container orchestration system. K8s is another name for Kubernetes. Kubernetes was initially developed by Google and is now managed by the Cloud Native Computing Foundation. Despite the fact that it now supports CRI-O in addition to the Docker runtime, w
3 min read
Kubernetes - Injecting ConfigMap in Pods
Pre-requisite: Kubernetes Leveraging the open-source container orchestration engine Kubernetes to automate the deployment, scalability, and management of applications. Another name for Kubernetes is K8s. Google originally created Kubernetes, which is currently overseen by the Cloud Native Computing Foundation. Despite the fact that it now works wit
3 min read
Kubernetes Deployments Best Security Practices with Manifest Files
Pre-requisites: Kubernetes The container orchestration technology Kubernetes makes it possible to deploy and manage applications in a containerized environment. To protect the security and integrity of your apps and data, it is crucial to follow security best practices, as with any technology. These are several security best practices for Kubernete
4 min read
Kubernetes Deployments - Security Best Practices
Pre-requisite: Kubernetes Applications can be more easily managed by Kubernetes, which automates operational tasks of container management and includes built-in commands for deploying applications, rolling out changes to your applications, scaling your applications up and down to fit changing needs, monitoring your applications, and more. Due to it
5 min read
How To Set Up Master-Slave Architecture Locally in Kubernetes?
Pre-requisite: Kubernetes Kubernetes is an open-source container orchestration system for automating containerized applications' deployment, scaling, and management. It was originally designed by Google and is now maintained by the Cloud Native Computing Foundation (CNCF). Kubernetes helps you deploy and manage containerized applications at scale m
5 min read
Kubernetes - Creating a ReplicaSet
Pre-requisite: Kubernetes A ReplicaSet is a key component of a Kubernetes application. It is a controller that ensures that a specified number of pod replicas are running at any given time. It is used to automatically replace any pods that fail, get deleted, or are terminated, ensuring the desired number of replicas are always available to serve re
9 min read
What is Azure Kubernetes Service?
Kubernetes is an open-source platform for automating the deployment, scaling, and management of containerized applications. It has become the de facto standard for managing containers in production and is used by organizations of all sizes to improve the speed and reliability of their application deployments. Azure Kubernetes Service (AKS)Azure Kub
6 min read
Kubernetes - Creating an App
Pre-requisite: Kubernetes In this article, we will discuss how to create a simple application on Kubernetes. Kubernetes is an open-source container orchestration system that helps to manage, deploy and scale containerized applications. Kubernetes provides a platform for automating the deployment, scaling, and operations of application containers ac
2 min read
How To Use Kubernetes Taints and Tolerations?
Kubernetes is an open-source Container Management tool that automates container deployment, container scaling, descaling, and container load balancing (also called a container orchestration tool). Suppose there is a scenario, you have a single cluster where you run all of your production, staging, and testing workloads. Our Productions nodes are of
5 min read
How to Use Kubernetes Annotations?
Annotations are key-value pairs that are used to attach non-identifying metadata to Kubernetes objects. Various tools that are built over Kubernetes use this metadata attached by annotations to perform actions or enhance resource management. Labels and Annotations are used to attach metadata to Kubernetes objects. This makes annotations important f
11 min read
Article Tags :