Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

cron - Kubernetes CronJob is executing 3 times instead of 1

I have a cronjob that I want to execute twice a day, at 7h and 19h.

Here is the definition.

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

Thing is when it runs, it runs 3 times :

  • at 2021-01-06T07:57:00Z
  • at 2021-01-06T07:58:00Z
  • at 2021-01-06T07:59:00Z

It is to be mentioned that my job execution time is about 22sec

Why is it happening ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The first item in a cron schedule is the minute. The first * in your cron schedule * 7,19 * * * matches every minute between 7:00 and 7:59 (and also every minute between 19:00 and 19:59). In therory, your cron job should not run twice, but 120 times per day using this schedule.

To execute your cron job at exactly 7:00 and 19:00, use 0 7,19 * * * as schedule.

For reference, the Kubernetes documentation on CronJob resources contains more information on the cron schedule format and itself links to the BSD cron documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...