job控制器是执行完一次任务,就结束;
cronjob控制器,是基于job控制器,定期频率性执行任务;等同于linux系统中的crontab一样;
[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
[root@k8s231 pi]# kubectl apply -f cronjob.yaml
[root@k8s231 pi]# kubectl get pods