Bboysoul's Blog

首页 公告 RSS

使用kubernetes的cronjob给你定时执行任务

June 15, 2021 本文有 296 个字 需要花费 1 分钟阅读

简介

我有很多需要定时执行的任务,大部分是定时去请求一个接口来更新或者获取数据,之前一直使用的是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


Tags:

本站总访问量 本站总访客数