error validating data in cronjob in kubernetes

8/9/2021

I am blocked with k8s cron job yaml syntax errros

I try to do

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

But i am getting this error:

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];
-- karlos
kubernetes

1 Answer

8/9/2021

Indentation of configMapRef name is incorrect, change this:

envFrom:
- configMapRef:
  name: test-config

to:

envFrom:
- configMapRef:
    name: test-config

Note: Also, your cron schedule is incorrect, you may need to fix 0 /5 * * * to a valid value. perhaps you need to set it to 0 */5 * * *

-- P....
Source: StackOverflow