If your team already runs a Kubernetes cluster, should the agent that summarises yesterday's tickets, triages alerts or drafts the morning report run there as a CronJob, or is a systemd timer on a small VM still the saner choice? Engineers argue about this in design reviews more than the problem deserves, mostly because each side imagines a different failure.

The person defending the timer imagines Kubernetes complexity: manifests, image builds, RBAC and a cluster upgrade that quietly breaks the job. The person defending the CronJob imagines the single VM that reboots during a kernel patch at 06:00 and nobody notices the report never arrived. Both failures are real.

The useful comparison is how each scheduler behaves when a model API is slow, a run overlaps with the next one, or a retry quietly multiplies the token bill. On those failures the two tools differ less than the debate suggests, and what difference remains comes down to two rows of the comparison below: who notices a dead host, and who limits retries.

What a daily agent job needs from its scheduler

An agent job is not a classic batch job. A nightly database dump either finishes or fails, and rerunning it costs a few minutes of CPU. An agent run calls a paid API dozens or hundreds of times, its duration varies with the size of the input and the latency of the provider, and it may take actions such as posting to Slack, opening tickets or sending email. Those side effects make a duplicate run worse than a missed one.

That gives five requirements. First, no overlap: if Monday's run is still going when Tuesday's starts, you get two agents writing to the same channel. Second, a hard timeout, because a stuck agent waiting on a hung HTTP connection should die, not run for nine hours. Third, deliberate retries: a retry should happen only for failures that are likely to be transient, and the number of attempts should be small.

Fourth, a clear answer to the missed-run question: when the machine or the cluster was down at the scheduled time, should the job run late or skip that day? Fifth, secrets and logs: the model API key must not sit in a world-readable file, and when a run produces a strange summary, someone needs the full log of the prompts and tool calls.

Write the five down for your own job before comparing tools; the answers differ for an agent that only reads and one that sends email to customers. Neither scheduler meets all five by default. Both can meet all five with configuration, and the difference lies in where that configuration lives and what breaks when it is wrong.

The systemd timer on one machine

A systemd timer is two small unit files on one host: a service that describes how to run the agent, and a timer that says when. Its strengths for an agent job are concrete.

Overlap is handled almost for free. When the timer fires and the service is still active from the previous run, systemd does not start a second copy. The timeout comes from TimeoutStartSec on a Type=oneshot service; when it expires, systemd stops the process.

Missed runs are explicit: with Persistent=true, a timer that should have fired while the machine was off fires once at the next boot, and without it the run is simply skipped. RandomizedDelaySec spreads start times so that several agents on the same host do not hit the provider at the same second.

Secrets can be passed with LoadCredential, which exposes a file to the service under a private directory instead of putting the key in an environment variable visible to other processes. Logs go to the journal, and journalctl -u with the unit name gives you every run.

[Service]
Type=oneshot
ExecStart=/opt/agent/run.sh
TimeoutStartSec=45min
LoadCredential=model_key:/etc/agent/model_key

[Timer]
OnCalendar=*-*-* 06:00:00
Persistent=true
RandomizedDelaySec=10min

The weakness is the host itself. One VM is one point of failure, and nothing outside it notices that the job did not run. You need an external check, such as a dead man's switch that alerts when no success ping arrived by 07:00. Retries are also on you: systemd can restart a failed oneshot with Restart=on-failure, but limiting the number of attempts per day takes more care than most teams give it.

The Kubernetes CronJob in an existing cluster

A CronJob creates a Job on a schedule, and the Job runs one or more pods until one succeeds. For a team that already deploys everything through manifests and GitOps, the agent becomes one more resource reviewed, versioned and rolled back the same way as the rest.

The fields that matter for an agent are few, and their defaults are where teams get hurt. The concurrencyPolicy field defaults to Allow, which means overlapping runs are permitted; set it to Forbid. The Job's backoffLimit defaults to 6, so a pod that fails is retried up to 6 more times with exponential backoff. For an agent that fails because the provider is returning errors, that is 7 attempts, each of which may spend tokens before it fails.

The activeDeadlineSeconds field on the Job gives a hard timeout for the whole Job, retries included. The startingDeadlineSeconds field controls missed runs: if the controller could not start the Job within that many seconds of the scheduled time, it skips the run. The timeZone field, stable since Kubernetes 1.27, lets you write the schedule in Europe/Lisbon instead of converting to UTC and getting it wrong twice a year.

Secrets come from a Secret object mounted as a file or injected as a variable, ideally synced from an external manager. Logs live in the pod until it is cleaned up, so you need a log pipeline; kubectl logs on a Job whose pods were garbage collected returns nothing. Keep successfulJobsHistoryLimit and failedJobsHistoryLimit at sensible values and ship logs to wherever the rest of your cluster logs go.

What you gain is resilience of the platform: if a node dies, the pod is scheduled elsewhere. What you pay is that the agent now depends on the image registry, the cluster's egress rules and the network policy, any of which can fail a run that would have worked on a plain VM.

Head to head on the five requirements

The comparison below assumes a team that already runs a cluster. For a team without one, Kubernetes for a single daily job is hard to justify.

Requirement systemd timer on one VM Kubernetes CronJob
No overlapping runs Default behaviour for an active oneshot service Needs concurrencyPolicy: Forbid, default is Allow
Hard timeout TimeoutStartSec on the service activeDeadlineSeconds on the Job, covers retries too
Retries Manual, Restart=on-failure plus your own limits backoffLimit, default 6, set it to 1 or 2
Missed run while down Persistent=true runs once at boot startingDeadlineSeconds decides, unset can mean surprise late runs
Time zone Host time zone or an explicit zone in OnCalendar timeZone field since 1.27
Secrets LoadCredential or a root-only file Secret object, ideally synced from a vault
Logs journald on the host Lost with the pod unless shipped
Host failure Job silently does not run Pod rescheduled on another node
Operational cost Two unit files, one VM patch cycle Image build, manifests, registry, network policy

Two lines decide most cases. If losing the host for a day would go unnoticed, the timer needs an external heartbeat whatever else you choose. If you would forget to change backoffLimit, the CronJob's defaults will cost you money the first time the provider has an outage. Everything else on the list is a one-line setting on either side, so do not let the table's length suggest that the choice is close on every row; it is close on most rows and decided by two.

The formula: what a retry policy costs in tokens

Retries look free in a manifest and are not free on an invoice. With independent failures, the expected number of attempts per day for a job that fails with probability p on each attempt and is allowed r retries is:

expected_attempts = (1 - p^(r + 1)) / (1 - p)
daily_cost        = expected_attempts x cost_per_attempt
worst_case_cost   = (r + 1) x cost_per_attempt

Take an illustrative agent that reads about 400,000 input tokens and writes 30,000 output tokens per run. At an illustrative price of $3 per million input tokens and $15 per million output tokens, one full attempt costs $1.20 plus $0.45, or $1.65. With p = 0.1 and r = 6, the expected number of attempts is about 1.11, so retries add roughly 18 cents a day. That is the comfortable case.

The uncomfortable case is correlated failure. When the provider has an outage, every attempt fails, often after spending most of its tokens, and the worst case of 7 attempts gives $11.55 for a run that produced nothing. Several agents with the same default on the same day can turn a provider incident into a noticeable line on the bill.

Mini-case (illustrative): a platform team at a Lisbon fintech moved six daily agents from cron on a shared VM into CronJobs. They copied a manifest from an old data pipeline that had backoffLimit unset.

During a four-hour provider incident, each of the six agents ran 7 times, partially processed its input each time and posted three half-finished summaries to Slack before its retries ran out. The fix took ten minutes: backoffLimit 1, concurrencyPolicy Forbid, activeDeadlineSeconds set to twice the median runtime, and an idempotency key on every Slack post.

Moving a daily agent from a timer to a CronJob, step by step

If the comparison points to the cluster, migrate deliberately. These steps assume the agent already runs reliably from a systemd timer.

  1. Measure the current job for two weeks: median and longest runtime, failure count, and tokens per run. You need these numbers to set the deadline and the retry limit.
  2. Make each run idempotent. Give every side effect, such as a message, a ticket or an email, a key built from the job name and the date, and skip the action if that key already exists.
  3. Package the agent as an image with a pinned base and a pinned model client version, and run it once by hand as a plain Job in a staging namespace.
  4. Write the CronJob with concurrencyPolicy: Forbid, backoffLimit of 1 or 2, activeDeadlineSeconds at about twice the longest observed runtime, startingDeadlineSeconds that matches your answer to the missed-run question, and an explicit timeZone.
  5. Mount the model key from a Secret, allow egress only to the provider's endpoints and to your own services, and confirm the pod can reach them.
  6. Ship pod logs to your central logging and add an alert for a Job that has not succeeded by its expected time.
  7. Run the CronJob in parallel with the timer for a week with side effects disabled, compare outputs and costs, then switch the timer off and remove its unit files.

Step 7 is the one teams skip, and it is the one that catches the egress rule nobody remembered to add.

The comparison so far treats a daily schedule as given, and that assumption is getting weaker. Many of these agents run at 06:00 only because something has to trigger them, while the work they do is really a reaction to events: tickets created, alerts fired, documents changed.

If an agent can be triggered by a queue and process items as they arrive, both the timer and the CronJob become the wrong primitive, and the real questions move to rate limits, backpressure and how many agent runs per hour your budget can absorb.

For the agents that do belong on a clock, the answer to the title follows from those two deciding rows. A team that already runs a cluster with central logging should use a CronJob with concurrencyPolicy Forbid, a backoffLimit of 1 or 2 and a deadline set from measured runtimes. A team without a cluster, or with a single agent, should keep the systemd timer and add the external heartbeat. Either way, write the retry limit first.