Job及CronJob:
---
apiVersion: batch/v1
kind: Job
metadata:
name: job-demo
spec:
template:
metadata:
name: job-demo
spec:
restartPolicy: Never
containers:
- name: counter
image: busybox
command:
- "/bin/sh"
- "-c"
- "for i in 9 8 7 6 5 4 3 2 1 ; do echo $i; done"
$ kubectl apply -f job-demo.yaml
$ kubectl get job
$ vim cronjob-demo.yaml
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: cronjob-demo
spec:
successfulJobsHistoryLimit: 10
failedJobsHistoryLimit: 10
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
metadata:
name: cronjob-demo
spec:
restartPolicy: Never
containers:
- name: counter
image: busybox
command:
- "/bin/sh"
- "-c"
- "for i in 9 8 7 6 5 4 3 2 1 0 -1 ; do echo $i; done"
spec.successfulJobsHistoryLimit和.spec.failedJobsHistoryLimit,表示历史限制,是可选的字段。它们指定了可以保留多少完成和失败的Job,默认没有限制,所有成功和失败的Job都会被保留。然而,当运行一个Cron Job时,Job可以很快就堆积很多,所以一般推荐设置这两个字段的值。如果设置限制的值为 0,那么相关类型的Job完成后将不会被保留
原文:https://www.cnblogs.com/fuyuteng/p/10917546.html