MoonitorMoonitor
All posts

Kubernetes CronJob Monitoring: How to Know When a Job Never Ran

Kubernetes CronJob monitoring: detect missed schedules and suspended jobs with heartbeat alerts, even when kubectl shows no failed Job or pod.

19 min read
Kubernetes CronJob Monitoring: How to Know When a Job Never Ran

Kubernetes CronJob Monitoring: How to Detect a Job That Never Ran

If you want to know whether a Kubernetes CronJob ran, kubectl can only tell you about the Jobs Kubernetes actually created, and only while they're still around. A CronJob that was skipped, suspended or never scheduled may leave no failed pod and no log. You might find a clue in Events or CronJob status, but nothing durable that alerts you. The fix is heartbeat monitoring. Your job pings an external URL when it finishes, and you get alerted when an expected ping doesn't arrive. That alert tells you a check-in is missing, not exactly why, so you still have to investigate. But the check lives outside the cluster, so it catches quiet failures that in-cluster tooling can miss, and it can still fire during a cluster outage.

That's the short version. Let's walk through why this happens, what the failure modes look like, and how to set up monitoring for scheduled jobs that you can actually trust.

How Kubernetes CronJobs fail quietly (and why that's the scary part)

Picture a team I'll call the nightly-backup team. Three months ago, during an incident, someone suspended the backup CronJob to free up cluster capacity. The incident ended, everyone went back to their day jobs, and nobody flipped suspend back to false. For three months the dashboards stayed green and everyone assumed the backups were fine. They found out when they needed a restore.

Nobody did anything unusual there. This isn't a sign you've set things up badly. It's just how scheduled work behaves when nothing is watching for absence.

Loud failures get noticed. A pod crashes, goes into CrashLoopBackOff, and a dozen tools light up. An absent run is different. You can't grep for something that never happened.

It helps to split the failures into two groups, because they leave different evidence.

When no Job is created, there's very little to inspect:

  • A suspended CronJob (suspend: true) starts no new Jobs, and it's easy to leave that on after maintenance.
  • If the controller was unavailable or fell behind, it may not have caught up on missed schedules.
  • When startingDeadlineSeconds expires, the run couldn't start within its allowed window, so it was dropped.
  • With concurrencyPolicy: Forbid, a run is skipped because the previous one is still going.

When a Job or pod exists but the work doesn't complete, there are clues, but nobody gets alerted:

  • With image pull errors, the pod exists but your code never starts. You'd see it in pod state and Events, if you looked in time.
  • When quotas or capacity run out, pods can't be created or scheduled. That usually shows up in Events.
  • A hung job leaves the pod running, so nothing looks broken, but the work never finishes.

Diagram: Diagram of a CronJob timeline showing scheduled runs as dots, with several highlighted as skipped or suspended and labelled with causes such as suspend flag, missed deadline and concurrency policy, with a note that no pod or log is created for the skipped runs for Kubernetes CronJob Monitoring: Know When a Job Never Ran

This is the heart of scheduled job monitoring. You're not watching for something bad to happen. You're watching for something good to not happen. That's a different problem, and it needs a different kind of tool.

Is kubectl and Job status enough for CronJob monitoring?

It's a fair question, and you're not being naive for asking. kubectl get cronjob, kubectl get jobs, kubectl describe and the controller logs are brilliant for debugging. They just weren't designed to be your alarm system.

The Kubernetes documentation is upfront that CronJob scheduling is approximate, and that in some circumstances a schedule can produce no Job, or more than one. That's why it recommends idempotent workloads. It also means the presence or absence of a Job object isn't a dependable record of whether your work happened.

Here's how the options compare:

Question kubectl / Job status In-cluster metrics (kube-state-metrics + Alertmanager) External heartbeat
Skipped run? Often no Job exists; status and Events may hint at why Possible with freshness rules you write yourself Detects a missing expected check-in; investigate to find the cause
Hung job? Only if you go looking Possible with duration rules Detectable if you also send a start signal and alert on a missing completion (see below)
History? Limited by history settings and TTL Depends on retention Depends on the monitor's incident history
Survives a cluster outage? No Not if the stack is down too The monitor does, provided the external service, network path and notification channel are healthy
Alerts on its own? No Yes, once configured Yes, once configured

Comparison: Comparison table with two columns, 'In-cluster tools (kubectl, kube-state-metrics)' and 'External heartbeat monitoring', and rows for detecting a skipped run, detecting a hung job, surviving cluster outage, history retention and alerting, using tick and cross icons for Kubernetes CronJob Monitoring: Know When a Job Never Ran

A few details are worth knowing.

Old evidence disappears. successfulJobsHistoryLimit and failedJobsHistoryLimit control how many finished Jobs are kept, and a TTL-after-finished setting can delete them sooner. If you rely on kubectl get jobs to prove last Tuesday's run happened, it may simply be gone.

Status fields help, but they aren't proof. CronJob status includes lastScheduleTime and lastSuccessfulTime, which are useful inputs. A recent schedule timestamp doesn't prove the workload succeeded, though, and you still have to interpret it against the schedule and a sensible grace period.

In-cluster monitoring shares a fate with the cluster. With Prometheus and kube-state-metrics you can write freshness alerts on those timestamps, and that's good practice. But if the cluster, the node pool or Prometheus itself goes down, those alerts can go quiet exactly when you need them.

So the gap is this: "Did the job run on time and finish?" benefits from an independent witness. Heartbeat monitoring is that witness. It narrows the investigation rather than replacing it.

Kubernetes CronJob missed schedules, suspension and concurrency policies

Before adding a heartbeat, it helps to understand the scheduling rules that cause skipped runs. This part is fiddly, and behaviour has shifted between Kubernetes versions, so please check the CronJob documentation for your cluster version before relying on the details below.

The 100 missed schedules rule

The CronJob controller checks for work roughly every 10 seconds. For each CronJob, it counts the scheduled start times it missed. If the count goes above 100, it doesn't start a Job and logs an error instead.

The detail that matters is which window gets counted. Without startingDeadlineSeconds, the controller looks back to the last schedule time it handled. With startingDeadlineSeconds set, it only counts misses within that many seconds before now. So a long gap on a frequent job, with no deadline set, can leave the controller refusing to catch up. A sensible deadline limits the window and avoids that.

Two situations look similar from the outside but aren't the same:

  • Suspension means you told the controller not to start Jobs. What happens on resume depends on your version and whether a deadline is set.
  • Controller or control-plane unavailability means the controller couldn't start anything, and it works out what to do when it returns.

Neither case is guaranteed to behave identically, and neither fails loudly. Test what happens on a non-critical CronJob in your own cluster, and read the controller logs for the "too many missed start time" message.

How startingDeadlineSeconds affects scheduled jobs

startingDeadlineSeconds sets how late the controller may start a Job after its scheduled time. It bounds catch-up after delays and changes the missed-schedule window described above.

The trap is setting it too short. Kubernetes warns that values below 10 seconds may not get scheduled at all, since the controller only checks about every 10 seconds. Even a modest value can drop runs if the control plane is busy for a moment, and a dropped run leaves no Job behind.

Allow, Forbid and Replace concurrency policies

  • Allow is the default. A new Job starts even if the previous one is still running, so you won't miss runs, but you might pile them up.
  • With Forbid, if the previous Job is still active, the new run is skipped and counted as missed. A frequent job that occasionally runs long will quietly skip intervals.
  • With Replace, the running Job is terminated and a new one starts. That suits "latest data wins" jobs, but a long task may never finish.

A skipped interval under Forbid isn't necessarily a scheduler problem. Sometimes the previous run is legitimately still working, and good monitoring helps you tell the difference.

The CronJob suspend flag

Setting spec.suspend: true stops new Jobs from starting, though it doesn't touch Jobs already created. It's the right tool during maintenance, and it's also the classic "we'll turn it back on later" item. Suspension can be intentional or accidental, so an absent Job doesn't tell you which one you're looking at.

CronJob time zones

By default, the schedule is interpreted in the time zone of the kube-controller-manager, which is often UTC, and you may not control that on a managed cluster. The timeZone field lets you pin a schedule to something like Europe/London.

This matters for UK teams. If you think in local time but the schedule runs in UTC, your 02:00 job shifts by an hour when the clocks change between GMT and BST. And if you set Europe/London, a time that doesn't exist (or happens twice) on clock-change night behaves in ways worth testing. A heartbeat expecting a ping at a fixed local time will show you this quickly.

How to add heartbeat monitoring to a Kubernetes CronJob

Now for the practical bit. It takes a few minutes per job.

Step 1: Create a heartbeat monitor

In Moonitor, create a cron/heartbeat monitor and you'll get a unique ping URL. The choice that matters is how the monitor decides a ping is due, because it changes how you set the grace period. Check which of these models your monitor offers:

  • A schedule-aligned monitor takes the cron expression and time zone, and expects a ping after each scheduled time, plus the grace period.
  • An interval-based monitor takes an interval (say 24 hours), and expects the next ping within that interval plus the grace period, counted from the previous ping.

Here's a worked example for a nightly backup at 02:00 Europe/London that normally takes 15 minutes and has never taken more than 40.

  • Schedule-aligned: the completion ping is normally due around 02:15. A grace period of 45 minutes means the alert fires at about 02:45 if nothing has arrived. That covers the longest run you've seen, plus some scheduling delay.
  • Interval-based: if the last ping arrived at 02:14, the next is expected 24 hours later. Runtime varies from night to night, so the grace period only needs to absorb that drift plus scheduling delay, and 30 minutes is a reasonable start. The catch is that detection can lag, because the clock runs from the previous ping, not from the scheduled start.

Whichever model you use, I'd treat these numbers as a first guess and tune them after a few weeks of real run times. Too tight and you'll train yourself to ignore alerts. Too loose and you'll hear about problems late.

Step 2: Store the heartbeat URL in a Secret

The ping URL is effectively a credential, since anyone who has it can fake a check-in. Keep it out of your manifests:

kubectl create secret generic heartbeat-urls \
  --from-literal=nightly-backup='https://your-unique-ping-url'

Step 3: Add the heartbeat ping to the job's command

Here's a minimal example that sends a success ping only after the work succeeds:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: nightly-backup
spec:
  schedule: "0 2 * * *"
  timeZone: "Europe/London"
  concurrencyPolicy: Forbid
  startingDeadlineSeconds: 600
  jobTemplate:
    spec:
      backoffLimit: 2
      template:
        spec:
          restartPolicy: OnFailure
          containers:
            - name: backup
              image: registry.example.com/backup:1.4
              command: ["/bin/sh", "-c"]
              args:
                - |
                  /scripts/run-backup.sh && \
                  { curl -fsS -m 10 --retry 3 -o /dev/null "$HEARTBEAT_URL" || true; }
              env:
                - name: HEARTBEAT_URL
                  valueFrom:
                    secretKeyRef:
                      name: heartbeat-urls
                      key: nightly-backup

Step 4: Send the ping from the same container, after the work

"Where in the container do I send the ping?" is the question I get asked most. Send it at the end of the main command, after the real work has succeeded, and from the same container. That's the simplest design that can't lie to you.

A sidecar can report outcomes too, but only if you explicitly coordinate it with the main container, for example through a shared volume or the exit status. Without that, it has no idea whether the job succeeded and may report success regardless, which is worse than no monitoring at all.

Step 5: Make sure the ping only fires on genuine success

The && chain does this job: the ping only runs if the backup script exits with status 0. For longer scripts, use set -e at the top, or wrap everything in a script that checks exit codes (we'll build one in the next section).

The || true after curl is a deliberate trade-off. A brief blip at the monitoring endpoint can't turn a successful backup into a failed, retried one. The flip side is a blind spot: if the ping fails, the job still exits cleanly. I'm fine with that, because the monitor will notice the missing check-in, and that alert is how you find out. Just make sure that alert path is one you've tested.

Step 6: Test Kubernetes CronJob monitoring by skipping a run

Don't trust it until you've seen it alert. Set suspend: true on a test CronJob (or just don't deploy one), wait past the grace period, and confirm the alert arrives in the channel you expect. Then unsuspend it and check the monitor recovers. It takes ten minutes, and it beats finding out during a real incident.

A note on minimal images

Distroless and scratch-based images often have no curl or wget. You can add a static curl binary, use your language's HTTP client for a one-line call at the end of your program, or use an init container to copy a binary into a shared emptyDir volume. Either way, keep the ping in the main container.

Reporting CronJob start, success and failure

A single success ping is a good start, but it can't separate "never started" from "started and hung". Both look like silence. Three signals help:

  • A start signal shows the container actually launched. If it's missing, look upstream: suspension, skipped schedule, image pull, quota.
  • A success signal shows the work finished cleanly.
  • A failure signal tells you straight away that the job ran and broke, without waiting for a grace period to expire.

Here's the catch that trips people up. A start ping must not be allowed to mask a missing completion. If your monitor treats any ping as "all good", a job that starts, hangs and never finishes will look healthy.

How you avoid that depends on what your monitor supports. Endpoint paths and signal semantics are product-specific, so check Moonitor's documentation rather than assuming one URL handles all three states. There are two safe designs:

  1. Native start/success/fail signals. If the monitor supports them, configure it to expect a completion within a maximum runtime after each start, and alert when that deadline passes. The start ping begins a running state, and only a success or failure ends it.
  2. Two separate monitors, which works with any simple heartbeat. A "started" monitor expects a ping shortly after the scheduled time, and a "completed" monitor expects a ping after the scheduled time plus your maximum runtime plus a buffer. A missing start points at scheduling or launch problems. A start with no completion points at a hang or a slow job.

If you only have a single monitor, the safest choice is to send just the success ping, and accept that missing and hung runs will both show up as a late check-in.

Diagram: Sequence diagram showing a CronJob pod sending a start ping, running the task, then sending either a success ping or a failure ping to an external heartbeat monitor, with a timer showing the expected check-in window for Kubernetes CronJob Monitoring: Know When a Job Never Ran

Here's a wrapper script for the two-monitor design. The environment variable names are placeholders for separate URLs you'd store in your Secret, and a failure URL is optional:

#!/bin/sh
## START_URL, SUCCESS_URL and FAIL_URL are illustrative: use the URLs
## (or signals) your monitor provides for each state.
ping() {
  [ -n "$1" ] && curl -fsS -m 10 --retry 3 -o /dev/null "$1" || true
}

ping "$START_URL"

if /scripts/run-backup.sh; then ping "$SUCCESS_URL" else code=$? ping "$FAIL_URL" exit "$code" fi

If your monitor supports it, include a short message or the exit code in the payload. An alert that says "nightly-backup failed, exit code 137" is much more useful at 7am than one that just says something's wrong.

One more decision is backoffLimit and retries. Do you want a failure ping for every attempt, or only the final outcome? For most teams, reporting only the final failure keeps things quiet, while a start ping on each attempt keeps the timing honest. Pick one and stick to it.

Alerting when a Kubernetes CronJob heartbeat doesn't arrive

Heartbeat monitoring flips the usual model. Instead of Moonitor reaching out to check something, the monitor expects a check-in and raises an incident when it's late. That matches the shape of the problem: no ping means something didn't happen, and your job is to find out what.

Infographic: Infographic showing the heartbeat alert flow: expected interval, grace period countdown, missed ping, multi-region verification, then alerts fanning out to email, Slack, Discord, Telegram and webhook icons for Kubernetes CronJob Monitoring: Know When a Job Never Ran

Routing scheduled job monitoring alerts

Not every job deserves a 3am phone call.

  • Email suits low-urgency jobs, like weekly report generation.
  • Slack, Discord or Telegram works for team visibility on things that matter during the working day.
  • Webhooks can feed your on-call tooling for the genuinely critical stuff, like backups and billing.

Keeping heartbeat alerts useful and reducing noise

A monitor that cries wolf is worse than none. Moonitor's outside-in checks are verified from multiple regions before alerting, so a one-off network hiccup doesn't wake someone up. Check the current docs for how confirmation works for heartbeat monitors specifically, since a missing ping is judged differently from a failed probe.

Look for patterns in incident history

Incident history is quietly one of the most useful parts. If a job is late every Monday after a deployment, or always runs long at month end, you'll see it in the history rather than in someone's fuzzy memory. If a critical job matters to other people, you can also surface it on a status page.

What if the Kubernetes cluster itself is down?

This is the question that makes heartbeat monitoring click for most people. If the cluster is down, no pings arrive, so the external monitor can still alert you. No agent inside the cluster has to survive for the alert to fire.

There are conditions, of course. That only holds if the external service, the network path and your notification channel are healthy. For critical workloads, I'd test the alert path periodically and make sure at least one channel doesn't depend on the infrastructure you're monitoring.

Compare that with in-cluster alerting, where Prometheus, Alertmanager and the notification path often run on the infrastructure that just failed.

When a cluster outage triggers forty heartbeat alerts at once, you want to know quickly that it's one big problem rather than forty small ones. That's why I like pairing heartbeats with outside-in checks:

  • HTTP/S and API monitoring on the services your cluster exposes, so you can tell "cluster down" from "one job broken".
  • Port and server monitoring for ingress endpoints and nodes you can reach directly.
  • SSL certificate monitoring on the same workloads, because a certificate-renewal CronJob that quietly stopped is a classic cause of an expiry surprise.
  • DNS monitoring to catch unexpected record changes that could send traffic, or your jobs' callbacks, somewhere unintended.

Keep in-cluster metrics and logs for the why once you know something is wrong.

Common Kubernetes CronJob monitoring pitfalls to avoid

I've made a few of these myself, so no judgement here.

  • Pinging only at the start and assuming it means success. A start ping proves launch, nothing more.
  • Pinging from a sidecar or preStop hook without coordination. These can fire regardless of the job's outcome.
  • Setting the grace period too tight. You'll get false alarms, then start ignoring the real ones.
  • Using bare curl. Use -fsS with a timeout and retries, so HTTP errors are visible and a flaky network doesn't hang the job.
  • Hard-coding ping URLs in manifests committed to Git. Use Secrets instead.
  • Sharing one monitor across several CronJobs or environments. One healthy job will mask another that has stopped.
  • Forgetting to update the monitor when you change the schedule. The CronJob moves from daily to hourly, the monitor still expects daily, and you've lost most of your coverage.
  • Treating the monitor as a replacement for logs. Heartbeats tell you something is wrong. Logs tell you why.

A simple rollout plan for scheduled job monitoring

You don't need to instrument every CronJob this afternoon. Here's a calmer approach:

  1. Inventory your CronJobs with kubectl get cronjobs -A and rank them by business impact. Backups, billing and data syncs come first.
  2. Add heartbeats to the top few, then tune grace periods after a week or two of real data.
  3. Set up alert channels and an escalation path, so it's clear who gets pinged, when, and where.
  4. Review incident history monthly and extend coverage to the next tier of jobs.

If you'd like to try it, Moonitor offers a free trial. Check the pricing page for current trial terms, plan limits and currency, since prices may be listed in USD rather than pounds.

Kubernetes CronJob monitoring FAQ

How do I know a Kubernetes CronJob didn't run at all?

Kubernetes alone won't reliably tell you, because a skipped or suspended run may create no Job at all. Events, CronJob status and controller logs can offer clues, but they aren't a durable alert. A heartbeat monitor alerts you when the expected ping doesn't arrive, and then you investigate the cause.

Isn't Job status in kubectl enough for monitoring?

It's excellent for debugging, but it only shows Jobs that exist and are still within your history limits, and it won't alert you on its own. An independent heartbeat gives you the alert, and kubectl helps you diagnose it.

Where in the container should I send the ping?

At the end of the main command, after the real work has succeeded, and ideally from the same container. You can add a start signal and a failure signal too, as long as a start ping can't mask a missing completion.

What if the Kubernetes cluster itself is down?

The heartbeat monitor sits outside the cluster, so a missing ping can still trigger an alert, as long as the monitoring service, network path and notification channel are healthy.

How long should the heartbeat grace period be?

It depends on whether your monitor is schedule-aligned or interval-based. For a schedule-aligned monitor, use your longest normal runtime plus a buffer for scheduling delay. For an interval-based one, cover the run-to-run variation plus that delay. Then tune it after a few weeks of real data.

Should I monitor every Kubernetes CronJob?

Start with the ones where a silent failure would hurt, such as backups, billing, data syncs and certificate renewals. Expand coverage as the process becomes routine.

Kubernetes CronJob monitoringscheduled job monitoring

Know before your users do.

Moonitor checks your sites, APIs and cron jobs around the clock, and verifies every failure from a second country before it ever pages you.