How to prevent a Cronjob execution in Kubernetes if there is already a job running

10/2/2018

I have to deploy a Cronjob in Kubernetes that will create a Job pod every 15 minutes. The job will check if a service is ready to provide new data. Once this service is ready, the job will take more than 1 hour to complete its execution. The problem revolves around the fact that other jobs are going to be executed during this time.

In short, how can I prevent a job to be executed in Kubernetes Cronjobs when there's already a Job running?

-- d4nielfr4nco
kubernetes
unix

1 Answer

10/2/2018

CronJob resource has a property called concurrencyPolicy, here an example:

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