Unable to Create Job From Cron Job: AKS Kubernetes version 1.21.1

Greg Van Riper 21 Reputation points
2021-08-24T18:44:10.07+00:00

I have setup a CronJob in AKS and I'd like to test to make sure the CronJob works correctly. When I try to create the job, it always returns with:

error: from must be an existing cronjob: no kind "CronJob" is registered for version "batch/v1" in scheme "k8s.io/kubectl/pkg/scheme/scheme.go:28"

I ran kubectl api-versions and confirmed the api version is correct.

kubectl get cronjobs -n <my namespace>

and confirmed it's there but when running this command:

kubectl create job --from=cronjob/<my job> <my job name> --namespace <my namespace>

this error is always returned. Note that I am on kubernetes version 1.21.1.

My CronJob API version is: batch/v1

Any insight on what I'm doing wrong would be appreciated.

Azure Kubernetes Service
Azure Kubernetes Service
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,458 questions
0 comments No comments
{count} votes

Accepted answer
  1. shiva patpi 13,366 Reputation points Microsoft Employee Moderator
    2021-08-24T23:35:06.467+00:00

    Hello @Greg Van Riper ,
    Can you try using apiVersion: "batch/v1beta1"

    Sample YAML file:

    apiVersion: "batch/v1beta1"
    kind: "CronJob"
    metadata:
    name: "sample-cron-job-nn"
    spec:
    concurrencyPolicy: "Forbid"
    schedule: "* * * * *"
    suspend: false
    jobTemplate:
    spec:
    template:
    spec:
    containers:
    - image: "mcr.microsoft.com/powershell"
    name: "sample-cron-job-nn-container"
    command: ["pwsh"]
    args: ["-Command","echo 'Hello World!!!'; exit 0"]
    restartPolicy: "OnFailure"

    //////////////////////////

    Sometimes you will get this error due to kubectl incompatible version.
    For example this is my local version :

    PS C:\aks> kubectl version
    Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.0", GitCommit:"af46c47ce925f4c4ad5cc8d1fca46c7b77d13b38", GitTreeState:"clean", BuildDate:"2020-12-08T17:59:43Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"windows/amd64"}
    Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.17", GitCommit:"68e3e47dad98b808ba41087c0c62e80cd4fcec36", GitTreeState:"clean", BuildDate:"2021-05-25T02:41:29Z", GoVersion:"go1.13.15", Compiler:"gc", Platform:"linux/amd64"}

    Let me know how it goes.

    Regards,
    Shiva.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.