0

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.

idan ahal
  • 707
  • 8
  • 21
  • 1
    As it's kubernetes, there are probably infinite ways of fixing this, strongly dependent upon how you're deploying (helm, kustomize, helmfile, curl, ...) so [edit your question](https://stackoverflow.com/posts/74636071/edit) and include what you've tried and the outcome that it's producing for you – mdaniel Dec 01 '22 at 02:13
  • I updated the question I hope it more clear. But basically, I don't care to work with helm if it can solve the problem or with any other solution. – idan ahal Dec 01 '22 at 10:02

2 Answers2

0

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

0

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 crontab 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

idan ahal
  • 707
  • 8
  • 21