Home > database >  Kubernetes - Handle cronjobs like crontab
Kubernetes - Handle cronjobs like crontab

Time:12-03

I have a lot of cronjobs I need to set on Kubernetes. I want a file to manage them all and set them to Kubernetes on deployment. I wish that if I remove a cron from that file it will be removed from Kubernetes too. Basically, I want to handle the corns like I'm handling them today on the machine (from a cron file that I would deploy). Add, remove and change crons.

I couldn't find a way of doing so. Does someone have an idea? Library or framework I can use like helm? Or any other solution.

CodePudding user response:

I highly recommend using gitops with argocd as a solution for Kubernetes configure management. Run crontab in deployment is a bad ideal because it hard to monitor your job result (cronjob job result can be get by kube-state-metrics exporter).

The ideal is packaging your manifest (it may be kubernetes manifest, kustomize, helm...etc...) -> put them to git -> argocd makes sure your configure deployed correctly

The advantages of gitops are include:

  • centralize your configuration
  • versioning your configuration
  • git authentication & authorization
  • traceable
  • multi-cluster deployment with argocd
  • automation deployment & sync
  • ...

Gitops is not a difficult and is the mordern way for kubernetes configure management. Let's try

CodePudding user response:

I found the solution that fits me. I used Helm to do so. I built a template to go over all crons (Which I inserted as values to the helm template (very similar to cron but more structured) - see in the example).

Then, all I need to do is run a helm upgrade with a new corn (values) file and it updates everything accordingly. If I updated, removed, or added a new corn everything is happening automatically and with versioning. You can also add a namespace to your cronjobs to make it more encapsulated.

Here is a very good and easy-to-understand example I used. And its git repo

  • Related