0

I have a couple (at some point many) k8s cron jobs, each with schedules like

*/5 * * * *  # Every five minutes
*/1 * * * *  # Every minute
*/1 * * * *
*/2 * * * *  # Every two minutes
...

My problem is that k8s seems to start them all at the top of the minute, so there might be a large number of jobs running at the same time. Each job only takes <10 seconds to run, so ideally, I would like to be able to distribute them over the span of a minute, i.e. delay their start.

Any ideas how to do that, given that k8s does not second-based schedule expressions?

silent
  • 14,494
  • 4
  • 46
  • 86

1 Answers1

1

You cant start a job indicating the seconds. What you can do is delaying each job with sleep . The pods of the cronjobs would start however together, but you can distributed the load of the jobs in this way.

apiVersion: batch/v1
kind: CronJob
metadata:
  name: myminutlyCronjob
spec:
  schedule: "1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: mycronjob
            image: myjobImage
            imagePullPolicy: IfNotPresent
            command: ["/bin/sh", "-c"]
            args:
            - sleep 10;
              mycronjobStartCommand;

          restartPolicy: OnFailure

Hope this can help you.

Ralle Mc Black
  • 1,065
  • 1
  • 8
  • 16