In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Job Resource Object
Pod containers for service classes: RC, RS, DS, Deployment.
Pod containers for work classes: Job---> execute once, or execute the processing program in batches, and push the container out after completion.
[root@master ~]# cat job.yaml
kind: Job
apiVersion: batch/v1
metadata:
name: test-job
spec:
template:
metadata:
name: test-job
spec:
containers:
name: hello
image: busybox
command: ["echo","hello k8s job! "]
restartPolicy: Never
[root@master ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
test-job-qgc6p 0/1 Completed 0 55s
[root@master ~]# kubectl logs test-job-qgc6p
hello k8s job!
PS: Note that if the task is executed incorrectly in the container, the container will be operated according to the restart policy of the container, but the restart policy of the container here can only be: Never, OnFailure
Improve Job Execution Efficiency
We can add parallelism to the Job.spec field. Indicates how many pods are running simultaneously to perform tasks
We can add the completions option to the Job.spec field. Indicates the total number of pods that need to be completed.
[root@master ~]# cat job.yaml
kind: Job
apiVersion: batch/v1
metadata:
name: test-job
spec:
completions: 8 //Total number of pods to complete
parallelism: 2 //run several pods simultaneously
template:
metadata:
name: test-job
spec:
containers:name: hello
image: busybox
command: ["echo","hello k8s job! "]
restartPolicy: OnFailure
How to perform a Job regularly
kind: CronJob
apiVersion: batch/v1beta1
metadata:
name: hello
spec:
schedule: "/1 *"
jobTemplate:
spec:
template:
spec:
containers:name: hello
image: busybox
command: ["echo","hello cronjob! "]
restartPolicy: OnFailure
[root@master ~]# kubectl apply -f cronjob.yaml
[root@master ~]# kubectl get cronjobs.batch
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
hello /1 * False 0 47s 51s
[root@master ~]# kubectl logs hello-1579053480-vpm6t
hello cronjob!
Looking at the status of the pods, you will see that a new Pod is running every minute to perform the tasks specified by the command.
Exercise:
Specify January 15, 2020 at 10:05 AM to run the crontab task above.
[root@master ~]# cat cronjob.yaml
kind: CronJob
apiVersion: batch/v1beta1
metadata:
name: hello
spec:
schedule: "5 10 15 1 3"
jobTemplate:
spec:
template:
spec:
containers:name: hello
image: busybox
command: ["echo","hello cronjob! "]
restartPolicy: OnFailure
At this point, it may be found that if a specific time is specified, the task may not be carried out.
[root@master ~]# kubectl api-versions //view api versions
Add the apiVersion library.
[root@master ~]# vim /etc/kubernetes/manifests/kube-apiserver.yaml
//add to yaml file
--runtime-config=batch/v2alpha1=true
Then restart the kubelet service and re-identify the api yaml file content.
//view api repository
[root@master ~]# kubectl api-versions
PS: Note that the job for the specified time still cannot run normally at this time, because k8s official has not perfected this function in the support of cronjob this resource object. Still to be developed.
Just like job resources, concurrent Job parameters are also supported under cronjob.spec.jobTemplate.spec: parallelism, and the total number of completed pods is also supported. Parameters: completions
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.