Set the concurrencyPolicy in a cronjob

0 votes

I cannot figure out how to set the concurrencyPolicy in a cronjob. I have tried variations of my current file config:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: job-newspaper
spec:
  schedule: "* */3 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
           - name: job-newspaper
            image: bdsdev.azurecr.io/job-newspaper:latest
            imagePullPolicy: Always
            resources:
              limits:
                cpu: "2048m"
                memory: "10G"
              requests:
                cpu: "512m"
                memory: "2G"
            command: ["spark-submit","/app/newspaper_job.py"]
          restartPolicy: OnFailure
          concurrencyPolicy: Forbid

When I run kubectl create -f ./job.yaml I get the following error:

error: error validating "./job.yaml": error validating data: 
ValidationError(CronJob.spec.jobTemplate.spec.template.spec): unknown 
field "concurrencyPolicy" in io.k8s.api.core.v1.PodSpec; if you choose 
to ignore these errors, turn validation off with --validate=false

I am probably either putting this property in the wrong place or calling it the wrong name, I just cannot find it in documentation. Thanks!

Sep 18, 2018 in Kubernetes by lina
• 8,220 points
2,195 views

1 answer to this question.

0 votes

The property concurrencyPolicy is part of the CronJob spec, not the PodSpec. You can locally see the spec for a given object using kubectl explain, like

kubectl explain --api-version="batch/v1beta1" cronjobs.spec

There you can see the structure/spec of the CronJob object, which in your case should be

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: job-newspaper
spec:
  schedule: "* */3 * * *"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        spec:
          containers:
           - name: job-newspaper
            image: bdsdev.azurecr.io/job-newspaper:latest
            imagePullPolicy: Always
            resources:
              limits:
                cpu: "2048m"
                memory: "10G"
              requests:
                cpu: "512m"
                memory: "2G"
            command: ["spark-submit","/app/newspaper_job.py"]
          restartPolicy: OnFailure
answered Sep 18, 2018 by Kalgi
• 52,350 points

Related Questions In Kubernetes

0 votes
1 answer

Running A cronjob in a pod in Kubernetes

Unfortunately, you cannot run the CronJob inside a container ...READ MORE

answered Sep 17, 2018 in Kubernetes by Kalgi
• 52,350 points
2,272 views
0 votes
1 answer

Environment Variables inside a Cronjob in Kubernetes

Ofcourse you can. Cron job specification is ...READ MORE

answered Sep 18, 2018 in Kubernetes by Kalgi
• 52,350 points
3,933 views
0 votes
1 answer

What's the difference betweena a deployment and a stateful set?

Both the deployments and replication controllers are ...READ MORE

answered Oct 3, 2018 in Kubernetes by ajs3033
• 7,300 points
4,459 views
0 votes
1 answer
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17, 2019 in Others by anonymous
15,456 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,024 views
0 votes
1 answer

Pods IP address from inside a container in the pod

Make sure that your pod yaml file ...READ MORE

answered Aug 29, 2018 in Kubernetes by Kalgi
• 52,350 points
2,431 views
0 votes
1 answer

Running a cronjob in kubernetes

You will find the CronJobresource in the batch/v1beta1 API group. ...READ MORE

answered Sep 6, 2018 in Kubernetes by Kalgi
• 52,350 points
760 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP