Kubernetes Cronjob triggers Job immediately even though the time exceeded

1/10/2020

I have Kubernetes job which runs every day at 5 AM. Today I wanted to change it to 6 AM. My current time is 10 AM.

As soon as modified the time from 5 AM to 6 AM, I noticed that Kubernetes Cronjob immediately triggers the job even though my current time is 10 AM.

What is the reason for this? Is there any parameter which can be used to enable/disable this behavior?

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: do-not-want-to-reveal
  namespace: default
spec:
  concurrencyPolicy: Forbid
  failedJobsHistoryLimit: 2
  jobTemplate:
    metadata:
      creationTimestamp: null
    spec:
      backoffLimit: 1
      template:
        metadata:
          creationTimestamp: null
        spec:
          containers:
          - image: myrepo/myimage:mytag
            imagePullPolicy: Always
            name: do-not-want-to-reveal
            resources: {}
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
          dnsPolicy: ClusterFirst
          restartPolicy: OnFailure
          schedulerName: default-scheduler
          securityContext: {}
          serviceAccount: myjob-sa
          serviceAccountName: myjob-sa
          terminationGracePeriodSeconds: 30
  schedule: 00 5 * * *
  successfulJobsHistoryLimit: 2
  suspend: false

Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", BuildDate:"2019-04-08T17:11:31Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.9", GitCommit:"16236ce91790d4c75b79f6ce96841db1c843e7d2", GitTreeState:"clean", BuildDate:"2019-03-25T06:30:48Z", GoVersion:"go1.10.8", Compiler:"gc", Platform:"linux/amd64"}
-- karthikeayan
kubernetes
kubernetes-cronjob

1 Answer

1/10/2020

This is known behavior with CronJob. It creates job for "missed" schedule. Have a look at this open issue - https://github.com/kubernetes/kubernetes/issues/63371

-- Shashank V
Source: StackOverflow