首页 > 解决方案 > 在 kubernetes 中验证 cronjob 中的数据时出错

问题描述

我被 k8s cron 作业 yaml 语法错误阻止

我试着做

kubectl apply -f cronjob.yaml

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: update-test
spec:
  schedule: "0 /5 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: update-test
            image: test:test
            imagePullPolicy: IfNotPresent
            command: ['echo test']
            envFrom:
              - configMapRef:
                name: test-config
              - configMapRef:
                name: test-config-globe
            resources:
                requests:
                  memory: "512Mi"
                  cpu: "0.5"
                limits:
                  memory: "1024Mi"
                  cpu: "2"
          restartPolicy: OnFailure

但我收到此错误:

error: error validating "deplyment.yaml": error validating data: [ValidationError(CronJob.spec.jobTemplate.spec.template.spec.containers[0].envFrom[0]): unknown field "name" in io.k8s.api.core.v1.EnvFromSource, ValidationError(CronJob.spec.jobTemplate.spec.template.spec.containers[0].envFrom[1]): unknown field "name" in io.k8s.api.core.v1.EnvFromSource];

标签: kubernetes

解决方案


名称缩进configMapRef不正确,更改此:

envFrom:
- configMapRef:
  name: test-config

到:

envFrom:
- configMapRef:
    name: test-config

注意:另外,您的cron日程安排不正确,您可能需要修复0 /5 * * *为有效值。也许您需要将其设置为0 */5 * * *


推荐阅读