In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
I. Overview of Job (1) Job
Job is responsible for handling short-lived one-time tasks, that is, tasks that are executed only once, and it ensures that one or more pod of the batch task ends successfully.
Kubernetes supports the following Job:
Non-parallel Job: usually create a Pod until it finishes successfully; Job with a fixed number of ends: add the completions field under the spec field. Create multiple Pod until the value specified by completions is met. If not, the default is 1; parallel Job with work queue: add the Parallelism field under the spec field. Indicates that several job are working in parallel. If it is not added, it is 1 by default
According to the completions field and Parallelism field that can be set, Job can be divided into the following categories:
(2) Job Controller
Job Controller is responsible for creating a Pod based on what is defined in the Spec field in the Job yaml file and continuously monitoring the status of the Job until it is successfully completed. If it fails, it is decided whether or not to create a new pod and retry the task based on restartPolicy (only OnFailure and Never are supported, not Always).
As shown in the figure:
(3) Application example
A simple little example:
[root@master job] # cat job.yaml kind: JobapiVersion: batch/v1metadata: name: test-jobspec: template: metadata: name: test-jobspec: containers:-name: hello image: busybox command: ["echo" "hello K8s job"] restartPolicy: Never [root@master job] # kubectl apply-f job.yaml / / generate Job resources [root@master job] # kubectl get job / / View JobNAME COMPLETIONS DURATION AGEtest-job 1 and 1 2s 5s [root@master job] # kubectl get pod-o wide / / View the details of Job operation NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATEStest-job-rq9ws 0 Completed 0 25s 10.244.1.15 node01 [root@master job] # kubectl logs test-job-rq9ws / / View the log information of Pod generated through Job hello k8s job [root@master job] # kubectl delete jobs test-job / / Delete Job Then the corresponding pod will also be deleted! (4) improve the execution efficiency of Job.
A simple little example:
[root@master job] # cat job.yaml kind: JobapiVersion: batch/v1metadata: name: test-jobspec: parallelism: 2 completions: 10 template: metadata: name: test-jobspec: containers:-name: hello image: busybox command: ["echo" "hello K8s job"] restartPolicy: Never [root@master job] # kubectl apply-f job.yaml [root@master job] # kubectl get jobNAME COMPLETIONS DURATION AGEtest-job 10lap 10 7s 15s// you can see that 10 tasks have been run
View the details of Job operation, as shown in the figure:
From this example, you can see:
Parallelism: indicates how many Pod are running simultaneously to execute tasks; completions: indicates the total number of pod that need to be completed
A simple little example:
[root@master job] # cat job.yaml kind: JobapiVersion: batch/v1metadata: name: test-jobspec: backoffLimit: 5 activeDeadlineSeconds: 100 template: metadata: name: test-jobspec: containers:-name: hello image: busybox command: ["echddddddo" "hello k8s job"] restartPolicy: Never [root@master job] # kubectl apply-f job.yaml [root@master job] # kubectl get jobNAME COMPLETIONS DURATION AGEtest-job 0Accord 1 2m28s 2m28s [root@master job] # kubectl get pod NAME READY STATUS RESTARTS AGEtest-job-4lzsc 0There 1 ContainerCannotRun 0 111stest-job-8q659 0lap 1 ContainerCannotRun 0 2m42stest-job-hjjbx 0/1 ContainerCannotRun 0 2m41stest-job-qcf4z 0/1 ContainerCannotRun 0 2m31s
As can be seen from this example:
BackoffLimit: indicates the number of error retries; activeDeadlineSeconds: indicates the time for Job to survive in the cluster
So much for a brief introduction to Job!
II. CronJob
CronJob is a scheduled task, similar to crontab in a Linux system, which runs a specified task in a specified period of time.
The schedule under the spec field in the CronJob yaml file is used to define the time interval and is used in the same way as crontab (minute, hour, day, month, week); the jobTemplate field specifies the task to be run
In kubernetes 1.15, the batch/v2alpha1 version of API is required to use CronJob, but kubernetes itself does not have this version, as follows:
[root@master job] # kubectl api-versions | grep batch/v2alpha1
You need to do the following to make the Kubernetes cluster support this batch/v2alpha1 version, as follows:
[root@master ~] # vim / etc/kubernetes/manifests/kube-apiserver.yaml add the following under the command field in the spec field:-runtime-config=batch/v2alpha1=true [root@master ~] # systemctl restart kubelet.service// restart the kubelet service [root@master ~] # kubectl api-versions | grep batch/v2alpha1batch/v2alpha1
In order to prevent errors in content addition, attach a picture:
(1) Application example [root@master job] # cat cronjob.yaml kind: CronJobapiVersion: batch/v2alpha1metadata: name: hellospec: schedule: "* / 1 *" jobTemplate: spec: template: spec: containers:-name: hello image: busybox command: ["echo", "hello cronjob"] restartPolicy: Never [root@master job] # kubectl apply-f cronjob.yaml
View the results:
There is no problem with this test, but if you specify a scheduled task, you will find that it will not work as expected!
As follows:
[root@master job] # cat cronjob.yaml kind: CronJobapiVersion: batch/v2alpha1metadata: name: hellospec: schedule: "18 16 15 13" jobTemplate: spec: template: spec: containers:-name: hello image: busybox command: ["echo" "hello cronjob"] restartPolicy: Never [root@master job] # date2020 Wednesday, January 15, 2001 16:18:48 CST [root@master job] # kubectl get podNo resources found.
This can be regarded as a small problem of K8s. Officials have been urgently fixing this problem. I believe this problem can be solved in the new version in the future.
Note that the specified time job is still not running properly at this time, because the K8s official has not improved this feature in the support of cronjob as a resource object. It has yet to be developed.
Like Job resources, CronJob also supports the concurrent Job parameter: parallelism, and also supports the total number of completed Pod parameters: completions!
So much for a brief introduction to CronJob!
-this is the end of this article. Thank you for reading-
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.