question

GregVanRiper avatar image
0 Votes"
GregVanRiper asked GregVanRiper commented

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

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

shivapatpi-MSFT avatar image
0 Votes"
shivapatpi-MSFT answered GregVanRiper commented

Hello @GregVanRiper ,
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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Shiva,
Thank you for the response. I actually updated kubectl on my client and that resolved it!

0 Votes 0 ·