轻量级前端框架助力开发者提升项目效率与性能
745
2022-11-08
k8s资源之job&cronjob
istio多集群探秘,部署了50次多集群后我得出的结论
istio多集群链路追踪,附实操视频
istio防故障利器,你知道几个,istio新手不要读,太难!
istio业务权限控制,原来可以这么玩
istio实现非侵入压缩,微服务之间如何实现压缩
不懂envoyfilter也敢说精通istio系列-filter-再也不用再代码里写csrf逻辑了
不懂envoyfilter也敢说精通istio系列filter
不懂envoyfilter也敢说精通istio系列-network filter-redis proxy
不懂envoyfilter也敢说精通istio系列-network filter-HttpConnectionManager
不懂envoyfilter也敢说精通istio系列-ratelimit-istio ratelimit完全手册
————————————————
job:
•Job负责批量处理短暂的一次性任务 (short lived one-off tasks),即仅执行一次的任务,它保证批处理任务的一个或多个Pod成功结束.
Job分类:
RestartPolicy:
•Never
•OnFailure
•如果RestartPolicy指定Never,则job会在pod出现故障时创建新的pod,且故障pod不会消失。.status.failed加1。
•如果RestartPolicy指定OnFailure,则job会在pod出现故障时其内部重启容器,而不是创建pod。.status.failed不变。
[root@master01 job]# cat busybox-never-job.yaml apiVersion: batch/v1kind: Jobmetadata: name: jobspec: template: spec: restartPolicy: Never containers: - name: job image: busybox command: ["echooo","Hello World"]
[root@master01 job]# cat busybox-onfailure-job.yaml apiVersion: batch/v1kind: Jobmetadata: name: jobspec: template: spec: restartPolicy: OnFailure containers: - name: job image: busybox command: ["echooo","Hello World"]
completions:
[root@master01 job]# cat busybox-completions-job.yaml apiVersion: batch/v1kind: Jobmetadata: name: jobspec: completions: 2 template: spec: restartPolicy: OnFailure containers: - name: job image: busybox command: - "sh" args: - "-c" - "sleep 30 && echo helloword"
parallelism:
[root@master01 job]# cat busybox-parallelism-job.yaml apiVersion: batch/v1kind: Jobmetadata: name: jobspec: parallelism: 2 template: spec: restartPolicy: OnFailure containers: - name: job image: busybox command: - "sh" args: - "-c" - "sleep 30 && echo helloword"
[root@master01 job]# cat busybox-completions-parallelism-job.yaml apiVersion: batch/v1kind: Jobmetadata: name: jobspec: parallelism: 2 completions: 2 template: spec: restartPolicy: OnFailure containers: - name: job image: busybox command: - "sh" args: - "-c" - "sleep 30 && echo helloword"
activeDeadlineSeconds:
[root@master01 job]# cat busybox-activeDeadlineSeconds.yaml apiVersion: batch/v1kind: Jobmetadata: name: jobspec: activeDeadlineSeconds: 20 completions: 2 template: spec: restartPolicy: OnFailure containers: - name: job image: busybox command: - "sh" args: - "-c" - "sleep 30 && echo helloword"
ttlSecondsAfterFinished:
•This field is alpha-level and is only honored by servers that enable the TTLAfterFinished feature.
•1.12版本之后,k8s提出了通过TTL自动删除Job的特性,当前仅对job生效,对 Complete 和 Failed 状态的Job都会自动删除
manualSelector:
使用batch/v1时,用户需要将jod的spec.manualSelector设置为true,才可以定制selector。默认为false
[root@master01 job]# cat busybox-selector.yaml apiVersion: batch/v1kind: Jobmetadata: name: jobspec: manualSelector: true selector: matchLabels: app: busybox template: metadata: labels: app: busybox spec: restartPolicy: Never containers: - name: job image: busybox command: ["echo","Hello World"]
backoffLimit:
•.spec.backoffLimit用于设置Job的容错次数,默认值为6。当Job运行的Pod失败次数到达.spec.backoffLimit次时,Job Controller不再新建Pod,直接停止运行这个Job,将其运行结果标记为Failure。另外,Pod运行失败后再次运行的时间间隔呈递增状态,例如10s,20s,40s
[root@master01 job]# cat busybox-backoffLimit.yaml apiVersion: batch/v1kind: Jobmetadata: name: jobspec: backoffLimit: 1 template: spec: restartPolicy: Never containers: - name: job image: busybox command: ["echooo","Hello World"]
命令:
•kubectl create job my-job --image=busybox – date
•kubectl create job my-job --image=busybox
•kubectl create job test-job --from=cronjob/a-cronjob
CronJob:
•CronJob即定时任务,就类似于Linux系统的crontab,在指定的时间周期运行指定的任务。
schedule:
[root@master01 cronjob]# cat schedule-cronjob.yaml apiVersion: batch/v1beta1kind: CronJobmetadata: name: cronjob1spec: schedule: "*/1 * * * *" jobTemplate: metadata: name: job spec: template: metadata: name: pod spec: restartPolicy: OnFailure containers: - name: busybox image: busybox command: ["echo","hello"] imagePullPolicy: IfNotPresent
backoffLimit:
[root@master01 cronjob]# cat backoffLimit-cronjob.yaml apiVersion: batch/v1beta1kind: CronJobmetadata: name: cronjob1spec: schedule: "*/1 * * * *" jobTemplate: metadata: name: job spec: backoffLimit: 1 template: metadata: name: pod spec: restartPolicy: OnFailure containers: - name: busybox image: busybox command: ["echooo","hello"] imagePullPolicy: IfNotPresent
suspend:
•.spec.suspend 字段也是可选的。如果设置为 true,后续所有执行都将被挂起。它对已经开始执行的 Job 不起作用。默认值为 false。
•kubectl patch cronjob cronjob1 -p '{"spec":{"suspend":false}}'
[root@master01 cronjob]# cat suspend-cronjob.yaml apiVersion: batch/v1beta1kind: CronJobmetadata: name: cronjob1spec: schedule: "*/1 * * * *" suspend: true jobTemplate: metadata: name: job spec: template: metadata: name: pod spec: restartPolicy: OnFailure containers: - name: busybox image: busybox command: ["echo","hello"] imagePullPolicy: IfNotPresent
completions:
[root@master01 cronjob]# cat completion-cronjob.yaml apiVersion: batch/v1beta1kind: CronJobmetadata: name: cronjob1spec: schedule: "*/1 * * * *" jobTemplate: metadata: name: job spec: completions: 2 template: metadata: name: pod spec: restartPolicy: OnFailure containers: - name: busybox image: busybox command: ["echo","hello"] imagePullPolicy: IfNotPresent
[root@master01 cronjob]# cat parallelism-cronjob.yaml apiVersion: batch/v1beta1kind: CronJobmetadata: name: cronjob1spec: schedule: "*/1 * * * *" jobTemplate: metadata: name: job spec: completions: 2 parallelism: 2 template: metadata: name: pod spec: restartPolicy: OnFailure containers: - name: busybox image: busybox command: ["echo","hello"] imagePullPolicy: IfNotPresent
concurrencyPolicy:
spec.concurrencyPolicy 字段也是可选的。它指定了如何处理被 Cron Job 创建的 Job 的并发执行。只允许指定下面策略中的一种:
Allow (默认):允许并发运行 Job
Forbid :禁止并发 运行 , 等待前一个执行完毕
Replace :取消当前正在运行的 Job ,用一个新的来替换
注意,当前策略只能应用于同一个 Cron Job 创建的 Job。如果存在多个 Cron Job,它们创建的 Job 之间总是允许并发运行。
[root@master01 cronjob]# cat concurrencyPolicy-allow-cronjob.yaml apiVersion: batch/v1beta1kind: CronJobmetadata: name: cronjob1spec: concurrencyPolicy: Allow schedule: "*/1 * * * *" jobTemplate: metadata: name: job spec: completions: 2 parallelism: 2 template: metadata: name: pod spec: restartPolicy: OnFailure containers: - name: busybox image: busybox command: ["echo","hello"] imagePullPolicy: IfNotPresent
[root@master01 cronjob]# cat concurrencyPolicy-forbid-cronjob.yaml apiVersion: batch/v1beta1kind: CronJobmetadata: name: cronjob1spec: concurrencyPolicy: Forbid schedule: "*/1 * * * *" jobTemplate: metadata: name: job spec: completions: 2 parallelism: 2 template: metadata: name: pod spec: restartPolicy: OnFailure containers: - name: busybox image: busybox command: - "sh" args: - "-c" - "sleep 70" imagePullPolicy: IfNotPresent
[root@master01 cronjob]# cat concurrencyPolicy-replace-cronjob.yaml apiVersion: batch/v1beta1kind: CronJobmetadata: name: cronjob1spec: concurrencyPolicy: Replace schedule: "*/1 * * * *" jobTemplate: metadata: name: job spec: completions: 2 parallelism: 2 template: metadata: name: pod spec: restartPolicy: OnFailure containers: - name: busybox image: busybox command: - "sh" args: - "-c" - "sleep 70" imagePullPolicy: IfNotPresent
startingDeadlineSeconds:
.spec.startingDeadlineSeconds 字段是可选的。它表示启动 Job 的期限(秒级别),如果因为任何原因而错过了被调度的时间,那么错过执行时间的 Job 将被认为是失败的。如果没有指定,则没有期限
activeDeadlineSeconds:
[root@master01 cronjob]# cat activeDeadlineSeconds-cronjob.yaml apiVersion: batch/v1beta1kind: CronJobmetadata: name: cronjob1spec: schedule: "*/1 * * * *" jobTemplate: metadata: name: job spec: activeDeadlineSeconds: 10 template: metadata: name: pod spec: restartPolicy: OnFailure containers: - name: busybox image: busybox command: - "sh" args: - "-c" - "sleep 30" imagePullPolicy: IfNotPresent
failedJobsHistoryLimit:successfulJobsHistoryLimit
•.spec.successfulJobsHistoryLimit 和 .spec.failedJobsHistoryLimit 这两个字段是可选的。它们指定了可以保留完成和失败 Job 数量的限制。
[root@master01 cronjob]# cat failedJobsHistoryLimit-cronjob.yaml apiVersion: batch/v1beta1kind: CronJobmetadata: name: cronjob1spec: failedJobsHistoryLimit: 2 schedule: "*/1 * * * *" jobTemplate: metadata: name: job spec: completions: 1 backoffLimit: 0 template: metadata: name: pod spec: restartPolicy: OnFailure containers: - name: busybox image: busybox command: ["echoioo","hello"] imagePullPolicy: IfNotPresent
[root@master01 cronjob]# cat successfulJobsHistoryLimit-cronjob.yaml apiVersion: batch/v1beta1kind: CronJobmetadata: name: cronjob1spec: successfulJobsHistoryLimit: 1 schedule: "*/1 * * * *" jobTemplate: metadata: name: job spec: completions: 2 template: metadata: name: pod spec: restartPolicy: OnFailure containers: - name: busybox image: busybox command: ["echo","hello"] imagePullPolicy: IfNotPresent
命令:
kubectl create cronjob my-job -- image= busybox
kubectl create cronjob my-job --image= busybox – date
kubectl create cronjob test-job --image= busybox --schedule="*/1 * * * *"
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~