no matches for kind "CronJob" in version "batch/v1"

5/13/2021

I use Kubernetes which v1.19.7, when I run the CronJob sample

apiVersion: batch/v1
kind: CronJob
metadata:
  name: express-learn-cronjob
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: hello
              image: busybox
              command:
                - /bin/sh
                - -c
                - date; echo Hello from the Kubernetes cluster
          restartPolicy: OnFailure

get unable to recognize "app-cronjob.yml": no matches for kind "CronJob" in version "batch/v1"

I can get the batch info by run kubectl api-versions | grep batch

batch/v1
batch/v1beta1

is there anything I missed? how can I fix it?

-- seven
kubernetes
kubernetes-cronjob

1 Answer

5/13/2021

For Kubernetes version 1.19.x you need to use batch/v1beta1 as apiVersion for your CronJob.

That is documented in the doc version 1-19:

https://v1-19.docs.kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/

It is stable only on k8s version 1.21.

-- Juliano Costa
Source: StackOverflow