Home > Mobile >  Unable to create a cronjob in k8s
Unable to create a cronjob in k8s

Time:02-15

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            

CodePudding user response:

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

CodePudding user response:

Cronjob belongs to batch/v1 k8s api. You should check api version before creating resources in any case they sometimes change.

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

CodePudding user response:

You can check the api-version of a resource with the

kubectl api-resources

command. In this case:

kubectl api-resources | grep cronjob | awk -v N=3 '{print $N}'

The output is 'batch/v1'.

  • Related