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,100 points
42 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 35,800 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
• 35,800 points
122 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
• 35,800 points
88 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,040 points
156 views
0 votes
1 answer
0 votes
1 answer
0 votes
3 answers

Error while joining cluster with node

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

answered Jan 17 in Others by anonymous
483 views
+3 votes
1 answer
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
• 35,800 points
29 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
• 35,800 points
17 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.