Openshift CronJob not starting for specific time schedule

4/30/2020

I'm currently trying to create a CronJob in Openshift that starts every day at 3.00 am. Creating the CronJob using a schedule with step values (e. g. "0 */1 * * *") works fine and the Jobs start correctly, however when creating the CronJob with a specific schedule such as "0 3 * * *" or "0 3 */1 * *", the CronJob won't start at all.

I checked the time stamps in the monitoring section and the time stamps are displayed in the same time zone as used for the CronJob schedule.

Any ideas on how to solve/work around this issue or if it is possible that CronJob uses a different time zone setting than displayed in the logs?

I am using openshift v3.9.102 and kubernetes v1.9.1+a0ce1bc657.

My CronJob configuration:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: update-prices
spec:
  schedule: "0 3 * * *"
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      template:
        metadata:
          labels:
            parent: "cronjobpcurl"
        spec:
          containers:
            - name: curljob
              image: curlimages/curl:latest
              command: ["curl", "--insecure", "https://www.example.com"]
              imagePullPolicy: Always
          restartPolicy: Never
-- erlDan
kubernetes-cronjob
openshift
openshift-3

1 Answer

4/30/2020

According to the documentation for CronJobs:

All cron job schedule times are based on the timezone of the master where the job is initiated.

So the first thing you might want to check is what timezone your OpenShift Master nodes have.

Then, check if your cronjob is running at all ("LAST SCHEDULE", here it ran 14s ago):

$ oc get cronjob
NAME            SCHEDULE     SUSPEND   ACTIVE   LAST SCHEDULE   AGE
my-cronjob      0 19 * * *   False     0        14s             3m

You can also use oc describe cronjob my-cronjob to see the Events and when the CronJob last ran. Plus it will also tell you when there has been an error:

$ oc describe cronjob my-cronjob
[..]
Last Schedule Time:  Thu, 30 Apr 2020 19:00:00 +0200
Active Jobs:         <none>
Events:
  Type    Reason            Age   From                Message
  ----    ------            ----  ----                -------
  Normal  SuccessfulCreate  80s   cronjob-controller  Created job my-cronjob-1588273680
  Normal  SawCompletedJob   70s   cronjob-controller  Saw completed job: my-cronjob-1588273680

If you cannot see anything in the Events, have a look at the OpenShift Controller logs, there you should see something like this:

controller.go:597] quota admission added evaluator for: {batch jobs}
event.go:221] Event(v1.ObjectReference{Kind:"CronJob", Namespace:"myproject", Name:"my-cronjob", UID:"8369a749-8b15-11ea-807e-080027e8770f", APIVersion:"batch/v1beta1", ResourceVersion:"3736", FieldPath:""}): type: 'Normal' reason: 'SuccessfulCreate' Created job my-cronjob-1588273680
controller.go:597] quota admission added evaluator for: {batch jobs}
event.go:221] Event(v1.ObjectReference{Kind:"Job", Namespace:"myproject", Name:"my-cronjob-1588273680", UID:"e9a3d2c5-8b15-11ea-807e-080027e8770f", APIVersion:"batch/v1", ResourceVersion:"3837", FieldPath:""}): type: 'Normal' reason: 'SuccessfulCreate' Created pod: my-cronjob-1588273680-q2tdc
[..]
-- Simon
Source: StackOverflow