Home > OS >  unable to create job from cronjob
unable to create job from cronjob

Time:02-04

When trying to create a job from an existing cronjob as follows:

kubectl create job --from=cronjob/my-job my-job-manual

I get the error that

Error from server (NotFound): cronjobs.batch "my-job" not found

Looking for the cronjob via kubectl get cronjob the cronjob is present in the output as expected.

By using kubectl get all I can also see the job listed under cronjob.batch/my-job. The create job command seems to however search under cronjobs.batch, which I suspect might be the cause for the error.

My question is how I can get create job to look for the cronjob in the correct place? Or is there an entirely different issue here altogether?

The versions of the k8s client and server are the same at v1.21.14.

CodePudding user response:

As per this doc, you might need to use the cron job on an adhoc basis in some cases. By creating a job from an existing cron job, you can accomplish this.

For instance, here's what we should do if you want a cron job to be started manually.

kubectl create job --from=cron job/kubernetes-cron-job manual-cron-job

--from=cron job/kubernetes-cron-job copies the cron job template and produces a job with the name manual-cron-job.

Note: Sometimes you will get this error due to the incompatible kubectl version

.

The main issue was the difference in version. Upgrade the server-side version and run the query again this will get executed without any problems.

Refer this doc to create custom cron job

Refer this Git link for more information

CodePudding user response:

The problem, despite all the apparent research into what might be the issue, was simply that the namespace for the command had a typo locally, while it was spelled correctly in all the commands that returned as expected.

  • Related