![](/style/images/good.png)
![](/style/images/bad.png)
使用kubernetes的cronjob给你定时执行任务
source link: https://www.bboy.app/2021/06/15/%E4%BD%BF%E7%94%A8kubernetes%E7%9A%84cronjob%E7%BB%99%E4%BD%A0%E5%AE%9A%E6%97%B6%E6%89%A7%E8%A1%8C%E4%BB%BB%E5%8A%A1/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
使用kubernetes的cronjob给你定时执行任务
发表于
2021-06-15 分类于 kubernetes
我有很多需要定时执行的任务,大部分是定时去请求一个接口来更新或者获取数据,之前一直使用的是xxl-job,但是这个跑在家里的树莓派中占用的资源很多,而且有时候会调度失败,所以就想着使用k8s的cronjob去给我调度任务
下面是示例yaml文件
apiVersion: batch/v1
kind: CronJob
metadata:
name: baidu-sign
namespace: cronjob
spec:
schedule: "33 8 * * *"
successfulJobsHistoryLimit: 5
failedJobsHistoryLimit: 5
jobTemplate:
spec:
template:
spec:
containers:
- name: baidu-sign
image: registry.bboysoul.cn/curlimages/curl:7.77.0
imagePullPolicy: IfNotPresent
command:
- 'curl'
- 'http://www.baidu.com'
restartPolicy: OnFailure
默认调用的时间都是使用UTC所以你会返现调用的时间会相差8小时,为了解决这个问题就需要给kube-controller-manager挂载/etc/localtime
vim /etc/kubernetes/manifests/kube-controller-manager.yaml
- hostPath:
path: /etc/localtime
type: FileOrCreate
name: localtime
- mountPath: /etc/localtime
name: localtime
readOnly: true
欢迎关注我的博客www.bboy.app
Have Fun
欢迎关注我的其它发布渠道
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK