Best Way of Implementing One Time Job On Exact Date (Exactly One Time Run) in Kubernetes

3/11/2019

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?

-- irvifa
kubernetes

1 Answer

3/11/2019

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

-- AhmetB - Google
Source: StackOverflow