kuberneteskubernetes-cronjob

Unable to create a cronjob in k8s


I am trying to create a cronjob , I have written a Springboot application for this and have created a abc-dev.yml file for application configuration

error: unable to recognize "src/java/k8s/abc-dev.yml": no matches for kind "CronJob" in version "apps/v1"

apiVersion: apps/v1
kind: CronJob
metadata:
  name: abc-cron-job
spec:
  schedule: "* * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          container:
          - name: abc-cron-job
            image: busybox
            imagePullPolicy: IfNotPresent
            command:
            - /bin/sh
            - -c
            - date; echo Hello from the Kubernetes cluster
          restartPolicy: OnFailure            

Solution

  • If you are running kubernetes 1.20 or lower, the correct apiVersion value is:

    apiVersion: batch/v1beta1

    If you are running kubernetes 1.21 or higher, its

    apiVersion: batch/v1