npocmaka
npocmaka

Reputation: 57332

Create job from cronjob in kubernetes .yaml file

I need to execute a job create from cronjob in kubernetes. Manualy I can run it like this:

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

Though I'm not sure how to translate this to yaml.

Probably I need to put a from: section in the spec ,but I'm not sure how.

Upvotes: 5

Views: 2643

Answers (1)

Vit
Vit

Reputation: 8491

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

You can use above method only to launch a job execution of a declared cronjob and whats more important(unfortunately for you) - you are able to that only using kubectl cli.

During research I also found my answer on a similar question Kubernetes Run job using CronJob . There is also try in that example to achieve very similar thing as you trying to rich(but vise-versa. In the provided example there is a try to create cronjob bases on already existed job)..

  jobTemplate:
    spec:
      labelSelector:
        name: pi # refer to the job created above

Both of your questions make sense, it would be very useful to have such an option, but, as I said in the beginning - that's currently not possible.

For test purposed - use provided command.

For regular usage - currently have no idea how to help you. Hope future releases will add this feature

Upvotes: 3

Related Questions