• Home
  • DevOps
  • Concept of Images and creating a Job in Kubernetes

Concept of Images and creating a Job in Kubernetes

Last updated on May 28 2022
Sankalp Rai

Table of Contents

Concept of Images and creating a Job in Kubernetes

Kubernetes – Images

Kubernetes (Docker) images are the key building blocks of Containerized Infrastructure. As of now, we are only supporting Kubernetes to support Docker images. Each container in a pod has its Docker image running inside it.
When we are configuring a pod, the image property within the configuration file has the equivalent syntax as the Docker command does. The configuration file has a field to define the image name, which we are planning to pull from the registry.
Subsequent is the common configuration structure which will pull image from Docker registry and deploy in to Kubernetes container.
apiVersion: v1
kind: pod
metadata:
name: Tesing_for_Image_pull ———–> 1
spec:
containers:
– name: neo4j-server ————————> 2
image: <Name of the Docker image>———-> 3
imagePullPolicy: Always ————->4
command: [“echo”, “SUCCESS”] ——————->
Within the above code, we have defined −
name: Tesing_for_Image_pull − This name is given to identify and check what is the name of the container that would get created after pulling the images from Docker registry.
name: neo4j-server − This is the name given to the container that we are trying to create. Like we have given neo4j-server.
image: <Name of the Docker image> − This is the name of the image which we are trying to pull from the Docker or internal registry of images. We need to define a complete registry path along with the image name that we are trying to pull.
imagePullPolicy − Always – This image pull policy defines that whenever we run this file to create the container, it will pull the equivalent name again.
command: [“echo”, “SUCCESS”] − With this, when we create the container and if everything goes fine, it will display a message when we’ll access the container.
In order to pull the image and create a container, we’ll run the subsequent command.
$ kubectl create –f Tesing_for_Image_pull
Once we fetch the log, we’ll get the output as successful.
$ kubectl log Tesing_for_Image_pull
The above command will produce an output of success or we’ll get an output as failure.
Note − It is recommended that you try all the commands yourself.

Kubernetes – Jobs

The main function of a job is to create one or more pod and tracks about the success of pods. They ensure that the specified number of pods are completed successfully. When a specified number of successful run of pods is completed, then the job is considered complete.

Creating a Job

Use the subsequent command to create a job −
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
Within the above code, we have defined −
kind: Job → We have defined the kind as Job which will tell kubectl that the yaml file being employed is to create a job type pod.
Name:py → This is the name of the template that we are using and the spec defines the template.
name: py → we have given a name as py under container spec which helps to identify the Pod which is going to be created out of it.
Image: python → the image which we are going to pull to create the container which will run inside the pod.
restartPolicy: Never →This condition of image restart is given as never which means that if the container is killed or if it is false, then it will not restart itself.
We’ll create the job using the subsequent command with yaml which is saved with the name py.yaml.
$ kubectl create –f py.yaml
The above command will create a job. If you want to check the status of a job, use the subsequent command.
$ kubectl describe jobs/py
The above command will create a job. If you want to check the status of a job, use the subsequent command.

Scheduled Job

Scheduled job in Kubernetes uses Cronetes, which takes Kubernetes job and launches them in Kubernetes cluster.
• Scheduling a job will run a pod at a specified point of time.
• A parodic job is created for it which invokes itself automatically.
Note − The feature of a scheduled job is supported by version 1.4 and the betch/v2alpha 1 API is turned on by passing the –runtime-config=batch/v2alpha1 while bringing up the API server.
We’ll use the equivalent yaml which we employed to create the job and make it a scheduled job.
apiVersion: v1
kind: Job
metadata:
name: py
spec:
schedule: h/30 * * * * ? ——————-> 1
template:
metadata
name: py
spec:
containers:
– name: py
image: python
args:
/bin/sh ——-> 2
-c
ps –eaf ————> 3
restartPocliy: OnFailure
Within the above code, we have defined −
schedule: h/30 * * * * ? → To schedule the job to run in every 30 minutes.
/bin/sh: This will enter within the container with /bin/sh
ps –eaf → Will run ps -eaf command on the machine and list all the running process inside a container.
This scheduled job concept is useful when we are trying to build and run a set of tasks at a specified point of time and then complete the process.
So, this brings us to the end of blog. This Tecklearn ‘Concept of Images and creating a Job in Kubernetes’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Kubernetes and build a career in DevOps domain, then check out our interactive, Continuous Orchestration using Kubernetes Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

Continuous Orchestration using Kubernetes

Continuous Orchestration using Kubernetes Training

About the Course

Tecklearn has specially designed this Continuous Orchestration using Kubernetes Training Course to advance your skills for a successful career in this domain. Kubernetes training helps you master the container orchestration tool. As part of the training, you will learn detailed Kubernetes, architecture of Kubernetes, what are Kubernetes Pods, node, how to deploy Kubernetes, creating a Kubernetes cluster, what are the various services available and how Kubernetes makes container orchestration simple. You will get an in-depth knowledge of these concepts and will be able to work on related demos. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Kubernetes.

Why Should you take Continuous Orchestration using Kubernetes Training?

• The average salary for people who possess Kubernetes as a skill is $117,000. – PayScale.com
• Apple, Capital One, AT&T, Oracle, Raytheon & many other MNC’s worldwide use Kubernetes across industries.
• The Kubernetes orchestration engine powers some of the biggest and most complex deployments in the world.

What you will Learn in this Course?

Introduction to DevOps
• What is Software Development
• Software Development Life Cycle
• Why DevOps?
• What is DevOps?
• DevOps Lifecycle
• DevOps Tools
• Benefits of DevOps
• How DevOps is related to Agile Delivery
• DevOps Implementation
Continuous Orchestration using Kubernetes
• Containers and Container Orchestration
• Introduction to Kubernetes
• Docker Swarm vs Kubernetes
• Kubernetes Architecture
• Deploying Kubernetes using Kubeadms
• Alternate ways of deploying Kubernetes
• Understanding YAML
• Creating a Deployment in Kubernetes using YAML
• Creating a Service in Kubernetes
• Installing Kubernetes Dashboard
• Deploying an App using Dashboard
• Using Rolling Updates in Kubernetes

0 responses on "Concept of Images and creating a Job in Kubernetes"

Leave a Message

Your email address will not be published. Required fields are marked *