0

I am trying to create a housekeeping job where I erase namespaces that have not been used for seven days. I have two options:

  1. I can use a Job, but I don't know how to make sure the Jobs are running on the date that I want.
  2. I read about CronJob. Unfortunately, CronJob in Kubernetes can only support 5 fields (default format). This means we can only define dates and months, but not years.

Which one is better to use?

ahmet alp balkan
  • 42,679
  • 38
  • 138
  • 214
irvifa
  • 1,865
  • 2
  • 16
  • 20

1 Answers1

1

Kubernetes CronJob API is very similar to cron as you said and doesn't have a year field.

If you need something that gets scheduled on time, you should write a kubernetes controlller that waits until the date you want, and then calls into Kubernetes API to create a Job object. This shouldn't be very complicated if you can program Go with the examples here: https://github.com/kubernetes/client-go

ahmet alp balkan
  • 42,679
  • 38
  • 138
  • 214
  • Yes, i'm actually also thinking about this, one thing that bugging me is if the effort of doing this would be too much. And if there's another approach of doing this. However thanks for your suggestions.. – irvifa Mar 14 '19 at 02:37
  • Running something in a precise time reliably is a non-trivial problem. Don’t expect the solution to be easy. :) At least I didn’t recommend the fact that you shouls probably run multiple replicas and do a leader election to see which replica must execute. – ahmet alp balkan Mar 14 '19 at 08:22