Search code examples
kuberneteskubernetes-helm

CronJob created as job in k8s 1.19.11


I have what seems like an API issue that results in not being to be able to create a job from a cron job.

I have a CronJob Helm file using the API like so:

apiVersion: batch/v1beta1
kind: CronJob

Deploying that with helm works just fine.

Then after it is deployed I attempt to create a job using that cronjob like so:

 kubectl create job $(helm-release-name) --from=cronjob/connector-config

This used to create the job based on the chart above. Now however, since upgrading to 1.19.11 I instead get this error:

##[error]error: unknown object type *v1beta1.CronJob
commandOutput
##[error]The process 
'/opt/hostedtoolcache/kubectl/1.22.1/x64/kubectl' failed with exit code 1

If I change the api in the Helm chart to this:

apiVersion: batch/v1
kind: CronJob

Then the Helm chart fails to deploy.

UPGRADE FAILED: unable to recognize "": no matches for kind "CronJob" in version 
"batch/v1"

Suggestions?

Thanks!


Solution

  • CronJobs is generally available (GA) in Google Kubernetes Engine (GKE) version 1.21 and later.

    the version you should use apiVersion: batch/v1

    https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/

    CronJobs was promoted to general availability in Kubernetes v1.21. If you are using an older version of Kubernetes, please refer to the documentation for the version of Kubernetes that you are using, so that you see accurate information. Older Kubernetes versions do not support the batch/v1 CronJob API.

    You can check the support Kubernetes API versions using

    kubectl api-resources OR kubectl api-versions
    

    you can also try

    kubectl explain <Resource type>
    
    kubectl explain cronjob