Cron jobs is one of my favorite feature in Kubernetes. I use them for backups, data retention, clean ups and some monitoring as well.
If you have Kubernetes setup by kubeadm, just find the file
Add a command argument to this Pod definition
After that restart kubelet.service (if on ubuntu)
sudo systemctl restart kubelet.service
Few caveats about Cron Jobs:
- Cron Jobs create Jobs. Jobs are running till successful completion. If your container constantly fails you will end up with a lot of failed containers. This is a proposal for this issue: Backoff policy and failed pod limit. While I was working on my cron jobs I ended up few times in this situation. To deal with that - delete the job and after that clean all pods created by that job
kubectl delete pod -l job-name=<job_name>
Dashboard does not support Cron Jobs, so you will not see them. But you will see the Jobs created by Cron Jobs.
concurrencyPolicywhich you want to apply. Default is
Allow. Most of Cron Jobs I created have
failedJobsHistoryLimit. These values are unset by default. I usually use