Kubernetes CronJob 执行了 3 次而不是 1 次

Kubernetes CronJob is executing 3 times instead of 1

我有一个 cronjob,我想每天执行两次,分别在 7 点和 19 点。

这是定义。

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: pamela
  namespace: influx
spec:
  schedule: "* 7,19 * * *"
  concurrencyPolicy: Replace
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - image: registry.gitlab.com/xxx/pamela:latest
            envFrom:
              - secretRef:
                  name: pamela-env
            name: pamela
            resources:
            volumeMounts:
            - mountPath: /raw
              name: pamela-claim
              subPath: raw
            - mountPath: /log
              name: pamela-claim
              subPath: log
          restartPolicy: Never
          volumes:
          - name: pamela-claim
            persistentVolumeClaim:
              claimName: pamela-claim
          nodeSelector:
            kops.k8s.io/instancegroup: nodes
          imagePullSecrets:
            - name: gitlab-registry

当它运行时,它会运行 3 次:

值得一提的是,我的作业执行时间约为 22 秒

为什么会这样?

cron 计划中的第一项是 分钟。您的 cron 计划 * 7,19 * * * 中的第一个 * 在 7:00 和 7:59 之间 每分钟 匹配(以及 [=29 之间的每一分钟=] 和 19:59)。理论上,您的 cron 作业不应该 运行 两次,而是每天使用此计划执行 120 次。

要在 7:00 和 19:00 执行您的 cron 作业,请使用 0 7,19 * * * 作为计划。

作为参考,Kubernetes documentation on CronJob resources contains more information on the cron schedule format and itself links to the BSD cron documentation.