当前位置:网站首页>【云原生之kubernetes】在kubernetes集群下的jobs与cronjobs管理
【云原生之kubernetes】在kubernetes集群下的jobs与cronjobs管理
2022-07-22 00:48:00 【江湖有缘】
【云原生之kubernetes】在kubernetes集群下的jobs与cronjobs管理
一、jobs与cronjobs介绍
1.job介绍
jobs:job负责处理任务,即仅执行一次的任务,它保证批处理任务的一个或多个Pod成功结束。
2.cronjobs介绍
CronJob在Job上加上了时间调度,CronJob是基于调度的Job执行将会自动产生多个job,调度格式参考Linux的cron系统。
二、检查本地kubernetes集群
1.检查工作节点状态
[[email protected]-master jobs]# kubectl get nodes -owide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
k8s-master Ready control-plane,master 18d v1.23.1 192.168.3.201 <none> CentOS Linux 7 (Core) 3.10.0-957.el7.x86_64 containerd://1.6.6
k8s-node01 Ready <none> 18d v1.23.1 192.168.3.202 <none> CentOS Linux 7 (Core) 3.10.0-957.el7.x86_64 containerd://1.6.6
k8s-node02 Ready <none> 18d v1.23.1 192.168.3.203 <none> CentOS Linux 7 (Core) 3.10.0-957.el7.x86_64 containerd://1.6.6
2.检查系统pod状态
[[email protected]-master jobs]# kubectl get pods -A -owide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
kube-system calico-kube-controllers-7bc6547ffb-2nf66 1/1 Running 2 (91m ago) 18d 10.244.235.201 k8s-master <none> <none>
kube-system calico-node-8c4pn 1/1 Running 2 (91m ago) 18d 192.168.3.202 k8s-node01 <none> <none>
kube-system calico-node-f28qq 1/1 Running 2 (91m ago) 18d 192.168.3.203 k8s-node02 <none> <none>
kube-system calico-node-wmc2j 1/1 Running 2 (91m ago) 18d 192.168.3.201 k8s-master <none> <none>
kube-system coredns-6d8c4cb4d-6gm4x 1/1 Running 2 (91m ago) 18d 10.244.235.200 k8s-master <none> <none>
kube-system coredns-6d8c4cb4d-7vxlz 1/1 Running 2 (91m ago) 18d 10.244.235.199 k8s-master <none> <none>
kube-system etcd-k8s-master 1/1 Running 2 (91m ago) 18d 192.168.3.201 k8s-master <none> <none>
kube-system kube-apiserver-k8s-master 1/1 Running 2 (91m ago) 18d 192.168.3.201 k8s-master <none> <none>
kube-system kube-controller-manager-k8s-master 1/1 Running 2 (91m ago) 18d 192.168.3.201 k8s-master <none> <none>
kube-system kube-proxy-8dfw8 1/1 Running 2 (91m ago) 18d 192.168.3.201 k8s-master <none> <none>
kube-system kube-proxy-ghzrv 1/1 Running 2 (91m ago) 18d 192.168.3.203 k8s-node02 <none> <none>
kube-system kube-proxy-j867z 1/1 Running 2 (91m ago) 18d 192.168.3.202 k8s-node01 <none> <none>
kube-system kube-scheduler-k8s-master 1/1 Running 2 (91m ago) 18d 192.168.3.201 k8s-master <none> <none>
三、查询k8s中jobs的相关模块
1.查询查询apiVersion
[[email protected]-master jobs]# kubectl api-resources |grep job
cronjobs cj batch/v1 true CronJob
jobs batch/v1 true Job
2.查询jobs
[[email protected]-master jobs]# kubectl explain jobs --recursive |more
KIND: Job
VERSION: batch/v1
DESCRIPTION:
Job represents the configuration of a single job.
FIELDS:
apiVersion <string>
kind <string>
metadata <Object>
annotations <map[string]string>
clusterName <string>
creationTimestamp <string>
deletionGracePeriodSeconds <integer>
deletionTimestamp <string>
finalizers <[]string>
generateName <string>
generation <integer>
labels <map[string]string>
managedFields <[]Object>
apiVersion <string>
fieldsType <string>
fieldsV1 <map[string]>
manager <string>
operation <string>
subresource <string>
time <string>
name <string>
namespace <string>
ownerReferences <[]Object>
apiVersion <string>
blockOwnerDeletion <boolean>
controller <boolean>
kind <string>
name <string>
uid <string>
resourceVersion <string>
selfLink <string>
uid <string>
spec <Object>
--More--
四、k8s中使用jobs创建一次性任务
1.编辑jobs.yaml文件
[[email protected]-master jobs]# cat jobs.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: jobs-tes
namespace: default
spec:
backoffLimit: 3
activeDeadlineSeconds: 120 #限制容器运行时间
# ttlSecondsAfterFinished: 10 #任务执行完成后,10s内会删除pod
# selector:
# matchLabels:
# app: helloworld
template:
metadata:
name: hellworld
labels:
app: helloworld
spec:
restartPolicy: Never
containers:
- name: helloworld
image: busybox:1.28
command:
- /bin/sh
- -c
- "echo 'hello the world'"
2.运行jobs
kubectl apply -f jobs.yaml
3.查看jobs
[[email protected]-master jobs]# kubectl get jobs.batch jobs-tes
NAME COMPLETIONS DURATION AGE
jobs-tes 1/1 19s 40s
4.查看运行日志
[[email protected]-master jobs]# kubectl logs jobs-tes-ns64n
hello the world
5.删除jobs
[[email protected]-master jobs]# kubectl delete jobs.batch jobs-tes
job.batch "jobs-tes" deleted
五、创建cronjobs类型任务
1.编写cronjobs.yaml文件
[[email protected]-master jobs]# cat cronjobs.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
name: cronjob-test
namespace: default
spec:
schedule: "*/1 * * * *"
successfulJobsHistoryLimit: 3 #保留成功任务的历史记录次数
# startingDeadlineSeconds:150 #上一个任务在150s后没有完成,进行下一个任务;在150s内,检测任务完成,立即执行下一个任务
jobTemplate:
metadata:
name: helloworld
spec:
backoffLimit: 3
activeDeadlineSeconds: 120 #限制容器运行时间
# ttlSecondsAfterFinished: 10 #任务执行完成后,10s内会删除pod
# selector:
# matchLabels:
# app: helloworld
template:
metadata:
name: hellworld
labels:
app: helloworld
spec:
restartPolicy: Never
containers:
- name: helloworld
image: busybox:1.28
command:
- /bin/sh
- -c
- "echo 'hello life'"
2.创建cronjobs
[[email protected]-master jobs]# kubectl apply -f cronjobs.yaml
cronjob.batch/cronjob-test created
3.查看cronjobs状态
[[email protected]-master jobs]# kubectl get cronjobs.batch cronjob-test
NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE
cronjob-test */1 * * * * False 0 38s 2m32s
4.查看任务完成状态
[[email protected]-master jobs]# kubectl get pods
NAME READY STATUS RESTARTS AGE
cronjob-test-27639747-9rbzx 0/1 Completed 0 2m21s
cronjob-test-27639748-hldht 0/1 Completed 0 81s
cronjob-test-27639749-jqbwk 0/1 Completed 0 21s
5.查看cronjobs日志
[[email protected]-master jobs]# kubectl logs cronjob-test-27639748-hldht
hello life
[[email protected]-master jobs]# kubectl logs cronjob-test-27639749-jqbwk
hello life
[[email protected]-master jobs]# kubectl logs cronjob-test-27639750-8brd4
hello life
边栏推荐
- AttributeError: ‘str‘ object has no attribute ‘param_group‘
- Which Hong Kong cloud server or physical server is more prone to downtime?
- 1. Monitoring concept
- DOM -- event chain (capture target and capture)
- [ERR] 1273 - Unknown collation: ‘utf8mb4_ 0900_ ai_ ci‘
- OA项目之项目简介&会议发布
- The way to practice and play strange: the method of detecting data types in JS
- Async function and await expression in ES6
- Qiu Chengtong college students' Mathematical Competition Mathematical Physics
- Test cases of common functions
猜你喜欢
Full link voltage test: the dispute between shadow database and shadow table
腾讯测试岗,被面试官虐哭...直到学长给了我这些知识点
酷早报:7月21日Web3加密行业新闻大汇总
SOC第一个工程
DOM -- event chain (capture target and capture)
Parker hydraulic oil pump pvp3336r2m
parker液压油泵PV140R1K1T1NMM1
51 MCU peripherals: Keys
Use of doccano data annotation platform
Redis data structure analysis (I)
随机推荐
rexroth比例阀4WRPEH6C3B04L-3X/M/24F1-885
rexroth力士乐柱塞泵A15VSO
3. ZABBIX installation
From 20s to 500ms, I used these three methods
The way to practice and play strange: the method of detecting data types in JS
MySQL index classification and its application examples
Ardunio development - pump operation process
实习打怪之路:JS中检测数据类型的方法
丘成桐大学生数学竞赛数学物理
With an annual salary of 30W, the growth path of software testers, at which stage are you?
Mysql索引分类及其使用实例
The overheated weather in the UK led to the interruption of Google cloud and Oracle cloud services
5.zabbix创建自定义key
Scheduling context of Kube scheduler
Address book (file version)
51 MCU peripherals: LED dot matrix
9.zabbix-SNMP监控
Kubernetes scheduling concept and workflow
测试的分类
1.监控概念