Run a Kubernetes CronJob every 30 seconds
Kubernetes has no exact expression for “Every 30 seconds”. Here is why, a workaround, and the platforms that can do it. A Kubernetes CronJob reads five-field cron in spec.schedule and starts a Job for each run.
Why Kubernetes can’t do this exactly
Defined on Quartz as */30 * * * * ? · “Every 30 seconds”
second: Kubernetes has no seconds field, so it cannot run at seconds other than 0.
WorkaroundRun every minute and repeat inside the job with sleep, or use a scheduler that has seconds (Spring, Quartz, a systemd timer).
Kubernetes gotchas
FAQ
What is the Kubernetes cron expression for “Every 30 seconds”?
There is none that matches exactly. Kubernetes has no seconds field, so it cannot run at seconds other than 0.
Which time zone does a Kubernetes schedule use?
Without spec.timeZone, in the local zone of kube-controller-manager, which is usually UTC. Set spec.timeZone (stable since Kubernetes 1.27) to an IANA name. CRON_TZ or TZ inside schedule is rejected.
Does a CronJob support @daily?
Yes. @yearly, @monthly, @weekly, @daily and @hourly work in spec.schedule.
Why did my CronJob run twice, or not at all?
A CronJob creates about one Job per scheduled time, not exactly one. Make the Job safe to repeat, and check startingDeadlineSeconds and concurrencyPolicy.