Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a kubernetes cronjob kind which allows multiple schedules for a single container image?

If one has an image with a number of different executables, is it possible to have multiple cron entries with different commands that run at different times in the same kubernetes deployment.

e.g. For some single container image named "jolly-roger", I want to schedule the following crontab, without having to manage 4 separate kubernetes applications in different repositories.

*/30 * * * * /pirate-bin/rehoist-the-flag
0 7,19 * * * /pirate-bin/feed-the-sharks
45 20 * * * /pirate-bin/count-the-gold
0 12 * * 1,5 /pirate-bin/make-landlubbers-walk-the-plank
like image 223
Rich Avatar asked Jun 21 '18 13:06

Rich


People also ask

What is difference between job and cronjob in Kubernetes?

Kubernetes Jobs Vs CronJobsKubernetes Jobs are used to constructing transitory pods that do the duties that have been allocated to them. CronJobs do the same function, except they run tasks on a predefined schedule.

What are Kubernetes CronJobs?

A CronJob creates Jobs on a repeating schedule. One CronJob object is like one line of a crontab (cron table) file. It runs a job periodically on a given schedule, written in Cron format.

Is cronjob heavy?

crontab as a system service is not heavy. the online cron-trigger-thingies exists just because most shared users are not allowed to create cron jobs. A cronjob is not more or less than a scheduled task and how expensive (ressource expensive) it is, depends on the task and its workload.


1 Answers

You can:

  • create a single cronjob resource with exactly one crontab time (like */30 * * * *) and several containers to run
  • create several cronjob resources using the same container images but different command and args for each job

You can not:

  • create one cron job resource with several crontab times
  • consequently not using multiple containers with multiple crontab times

So in short, you can place all your binaries in a single container, but cannot solve your problem by defining one resource. The way to go is to use the same image in a distinct cronjob resource per crontab line of your example

like image 148
David Steiman Avatar answered Sep 21 '22 10:09

David Steiman