I am on Kubernetes. I need to be able to write and run cron jobs in a pod. I can't use the CronJob workload. The solution I found is to run cron jobs from a cron sidecar container. I write cron jobs to /etc/crontab and run them with chroot. Although, I can run chroot commands from the command line, it doesn't seem to work as a cron job.
Example: This works when I run it in the shell.
# chroot /proc/151/root bash -c 'echo $(date) this is a command executed in cron sidecar >> /proc/151/root/var/log/cronjob.log' cronjob.log: Mon Apr 14 15:44:34 UTC 2025 this is a command executed in cron sidecar
Doesn't work when I put this line in /etc/crontab in cron sidecar container.
* * * * * root chroot /proc/151/root bash -c 'echo $(date) this is a cron job executed by cron sidecar >> /proc/151/root/var/log/cronjob.log' crond is running.
# pgrep cron 347 What's wrong with this cron job? How can I make this work?