kubernetes 中建立定时任务CronJob
1.yaml 文件示例:apiVersion: batch/v1beta1kind: CronJobmetadata:name: crontab-jobspec:schedule: "1 5 * * *"jobTemplate:spec:template:spec:containers:...
·
1.yaml 文件示例:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: crontab-job
spec:
schedule: "1 5 * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: crontab-job
image: 'your-domain.com/your-project-path:version'
args:
- /usr/bin/php
- /www/demo.php
imagePullSecrets:
- name: secret
restartPolicy: OnFailure
2.解释
上述yaml意义:每天5点1分开出一个pod,该pod的image来源于:your-domain.com/your-project-path:version。执行命令: /usr/bin/php /www/demo.php
3.补充
(1)
文档中提到,默认只会开出一个pod执行定时任务:
https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/
For a Non-parallel job, you can leave both .spec.completions and .spec.parallelism unset. When both are unset, both are defaulted to 1.
(2)
.spec.schedule 的设置方式于Linux中crontab的设置一样。
更多推荐
已为社区贡献2条内容
所有评论(0)