silent
silent

Reputation: 16218

Kubernetes CronJobs - not start at the top of the minute

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?

Upvotes: 0

Views: 347

Answers (1)

Ralle Mc Black
Ralle Mc Black

Reputation: 1203

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.

Upvotes: 2

Related Questions