job控制器是执行完一次任务,就结束;
cronjob控制器,是基于job控制器,定期频率性执行任务;等同于linux系统中的crontab一样;
1,编辑cronjob资源清单
[root@k8s231 pi]# vim cronjob.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
name: xinjizhiwa
spec:
schedule: "* * * * *"
#定义job的模板
jobTemplate:
spec:
template:
spec:
containers:
- name: c1
image: alpine:latest
#执行命令,也是任务
command:
- /bin/sh
- -c
- date; echo hello xinjizhiwa, you are my friend;
restartPolicy: OnFailure
2,创建cronjob资源
[root@k8s231 pi]# kubectl apply -f cronjob.yaml
3,查看pod
4,查看pod
[root@k8s231 pi]# kubectl get pods