A Job creates one or more Pods and ensures a specified number of them successfully terminate. You can also use a Job to run multiple Pods in parallel. For example, we can use Kubernetes Job to process and analyze data in batch.
This tutorial describes the basic features of a Job by creating a parallel job to compute π to 2000 places and print it out.
project-regular
account. Please refer to the Getting Started with Multi-tenant Management if not yet.project-admin
account and invite project-regular
to enter the corresponding project if not yet. Please refer to Invite Member.About 15 minutes
Log in the KubeSphere console with project-regular
account, then enter a project, navigate to Application Workloads → Jobs and click Create Job. Then fill in the basic information, e.g. job-demo
as its name, and choose Next.
Set the four configuration parameters of the Job Spec as the following shown.
5
.4
.2
.300
.then click Next when you are done.
Leave the RestartPolicy as Never, then click Add Container Image.
- Never: The job will create a new container group when the errors occur and it will not disappear.
- OneFailure: The job will restart the container when the errors occur, instead of creating a new container group.
Enter perl
in the image name and press return key, then scroll down to Start Command.
Check Start Command, add the following command which performs a simple calculation and outputs the result of the Pi to 2000 places. Then click √ to save it and choose Next to finish this step.
perl,-Mbignum=bpi,-wle,print bpi(2000)
Click Next to skip Mount Volumes. Click Create to complete job creation.
job-demo
and inspect the execution records. You can see it displays "completed". There are four completed Pods since the Completions was set to 4
in the Step 2.Tips: Since the creation of the container may encounter timed out, if the job fails, click ··· → Rerun from the list to rerun this job.
Congratulation! You have learned Job's basic functions. For further details, please refer to Jobs - Run to Completion.