Schedule pod to run every X minutes

8/14/2018

I have a program that executes some code, sleeps for 10 minutes, then repeats. This continues in an infinite loop. I'm wondering if theres a way to let Kubernetes/GKE handle this scheduling.

I see that GKE offers cron scheduling. I could schedule a pod to run every 10 minutes. The problem is that in some scenarios the program could take more than 10 minutes to complete.

Ideally, I could let the pod run to completion, schedule it to run in 10 minutes, repeat. Is this possible?

Is this possible on Kubernetes?

-- sthomps
google-kubernetes-engine
kubernetes

1 Answer

8/14/2018

In K8S there's a specific resource for that goal: CronJob

In the following example you see a schedule section with the tipical cron notation:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: your-cron
spec:
  schedule: "*/20 8-19 * * 1-5"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        metadata:
          labels:
            app: your-periodic-batch-job
        spec:
          containers:
          - name: redmine-cron
            image: your_image
            imagePullPolicy: IfNotPresent
          restartPolicy: OnFailure
-- Nicola Ben
Source: StackOverflow