Warm tip: This article is reproduced from serverfault.com, please click

kubernetes-如何在GKE中正确执行cron任务

(kubernetes - How to properly do cron task in GKE)

发布于 2020-11-28 09:18:02

借助App Engine GAE,我们通常会提供具有不同cron任务的yaml,如下所示:

cron:
# Notifications Job
- description: "Remove Notifications Cron Weekly run"
  url: /tasks/notifications
  schedule: every monday 09:00
  timezone: Australia/NSW
# Jobs job
- description: "Remove Deleted Jobs / completed"
  url: /tasks/jobs/deleted_completed_drafts
  schedule: every monday 09:00
  timezone: Australia/NSW
# Marketplace job
- description: "Remove Deleted Products / soldout"
  url: /tasks/products/deleted_soldout_drafts
  schedule: every monday 09:00
  timezone: Australia/NSW

我搬到了GKE,但现在还无法确切地知道如何从一个文件中运行上述cron任务:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: Cron Task
spec:
  schedule: "*/1 0 0 * * 0" #"*/1 * * * *"
  startingDeadlineSeconds: 104444
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: callout
            image: gcr.io/my-site/mysite-kubernetes:v0.0.16
            args:
            - /bin/sh
            - -ec
            - curl https://www.ksite.com/tasks/notifications
          restartPolicy: Never

那么,如何安排GKE Cron文件来容纳上述所有任务?我必须为每个不同的任务编写不同的代码吗?

时间表应为每个星期一09:00时区:澳大利亚/新南威尔士州。时间表是否正确表示了“ * / 1 0 0 * * 0”

我是否必须指定图像,导致Web部署脚本已经指定了图像?

Questioner
LearnToday
Viewed
11
user140547 2020-11-29 04:11:24

我对App Engine不太熟悉,但是

  • 所有CronJob时间表:时间基于文档中的kube-controller-manager的时区
  • 你不需要你的应用程序图像即可进行curl调用。卷曲图像可能就足够了
  • 如果CronJob程式与应用程式在同一个丛集中执行,则你无需遍历Loadbalancer,也可以使用类似的服务http://service-name/tasks/notifications
  • 写三个可能Cronjobs比尝试将所有三个调用都塞成一个更好