设置并发Kubernetes Cronjob

时间:2018-01-14 18:51:37

标签: kubernetes

这是一个非常基本的问题,我似乎无法找到答案,但我无法弄清楚如何在cronjob中设置concurrencyPolicy。我尝试过当前文件配置的变体:

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

当我运行kubectl create -f ./job.yaml时,我收到以下错误:

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

我可能要么将此属性放在错误的位置,要么将其命名为错误名称,我只是在文档中找不到它。谢谢!

1 个答案:

答案 0 :(得分:5)

属性concurrencyPolicy是CronJob规范的一部分,而不是PodSpec。您可以使用kubectl explain在本地查看给定对象的规范,例如

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

在那里你可以看到CronJob对象的结构/规范,在你的情况下应该是

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