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

Kubernetes 如何在GKE中正确执行cron任务,kubernetes,cron,google-kubernetes-engine,Kubernetes,Cron,Google Kubernetes Engine,使用App Engine GAE,我们通常会有yaml,其中包含不同的cron任务,如下所示: cron: # Notifications Job - description: "Remove Notifications Cron Weekly run" url: /tasks/notifications schedule: every monday 09:00 timezone: Australia/NSW # Jobs job - description: &

使用App Engine GAE,我们通常会有yaml,其中包含不同的cron任务,如下所示:

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
 ┌───────────── minute (0 - 59)
 │ ┌───────────── hour (0 - 23)
 │ │ ┌───────────── day of the month (1 - 31)
 │ │ │ ┌───────────── month (1 - 12)
 │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
 │ │ │ │ │                                   7 is also Sunday on some systems)
 │ │ │ │ │
 │ │ │ │ │
 0 9 * * 1 <command to execute>
我搬到了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时区:澳大利亚/新南威尔士州。附表:“*/10 0**0”是否正确表示了这一点


我是否必须指定映像,因为web部署脚本已经指定了映像?

我对App Engine不太熟悉,但是

  • 所有
    CronJob
    计划:时间基于kube控制器管理器的时区,根据
  • 您不需要应用程序映像来执行curl调用
  • 如果
    CronJob
    与应用程序在同一集群中运行,您不需要通过负载均衡器,也可以像
    http://service-name/tasks/notifications
  • 编写三个
    Cronjobs
    可能比将所有三个调用塞进一个调用要好
    • kubernetes中使用标准语法:

      否则,您可以使用任何包含curl的图像(如已建议的)

      关于:

      写三份工作可能比把所有的工作都塞满要好 三通电话合一

      我还强烈建议您使用3个独立的
      CronJobs
      ,因为如果运行这些作业时出现任何问题,这种方法更简单,也更容易排除故障

       ┌───────────── minute (0 - 59)
       │ ┌───────────── hour (0 - 23)
       │ │ ┌───────────── day of the month (1 - 31)
       │ │ │ ┌───────────── month (1 - 12)
       │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
       │ │ │ │ │                                   7 is also Sunday on some systems)
       │ │ │ │ │
       │ │ │ │ │
       0 9 * * 1 <command to execute>
      
      args:
      - /bin/sh
      - -c
      - /full/path/to/script.sh