job.yml
job.yml
apiVersion: batch/v1
kind: Job
metadata:
name: myjob
spec:
completions: 6
parallelism: 2
template:
metadata:
name: myjob
spec:
containers:
- name: hello
image: busybox
command: ["echo","hello k8s i love you"]
command: ["echo","hello k8s i love me"]
restartPolicy: Never
cronjob.yml
#定时任务 cronjob
#如果失败 失败了。这是因为 Kubernetes 默认没有 enable CronJob 功能,需要在 kube-apiserver 中加入这个功能。
#方法很简单,修改 kube-apiserver 的配置文件 /etc/kubernetes/manifests/kube-apiserver.yaml:
#在spec的command:下添加 - --runtime-config=batch/v2alpha1=true
示例:
apiVersion: batch/v2alpha1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
command: ["echo","hello k8s i love you"]
restartPolicy: OnFailure
![](https://www.cnblogs.com/images/cnblogs_com/luoyan01/1311964/t_webwxgetmsgimg.jpg)
![](https://www.cnblogs.com/images/cnblogs_com/luoyan01/1311964/t_qq.jpg)