Kubernetes CronJob monitoring: get alerted when a CronJob fails or doesn't run
kubectl shows you what happened if you go and look. Nobody goes and looks at a nightly backup CronJob until the day they need the backup. Here is how CronJobs go quiet, and a one-line heartbeat that tells you within minutes.
How a CronJob goes quiet
- The start deadline passes. With
startingDeadlineSecondsset, a run that can't start in time (controller down, cluster busy, node pressure) is skipped and counted as missed. - Too many missed schedules. If the controller counts more than 100 missed schedules, it stops starting the CronJob and only logs an error event (see the Kubernetes CronJob docs).
- Overlapping runs are skipped. With
concurrencyPolicy: Forbid, a long run silently swallows the next one. - Someone set
suspend: trueduring an incident and forgot to undo it. - The Job keeps failing. Image pull errors, bad credentials or a full disk; after
backoffLimitretries the Job is marked failed, and old failures are cleaned up byfailedJobsHistoryLimit.
In all of these cases nothing pages you unless you already run alerting on Kubernetes events or kube-state-metrics. A heartbeat covers them all from outside the cluster: if the "it worked" ping doesn't arrive on time, you get an alert.
Add a heartbeat to the CronJob
Create a free check in CronBeat with the same period as your schedule, then ping it at the end of the command. Success pings the plain URL; a failure pings /fail for an immediate alert.
apiVersion: batch/v1
kind: CronJob
metadata:
name: nightly-backup
spec:
schedule: "0 3 * * *"
timeZone: "Etc/UTC"
startingDeadlineSeconds: 600
concurrencyPolicy: Forbid
jobTemplate:
spec:
backoffLimit: 2
template:
spec:
restartPolicy: Never
containers:
- name: backup
image: your-backup-image
env:
- name: CRONBEAT_KEY
valueFrom:
secretKeyRef: { name: cronbeat, key: ping-key }
command: ["/bin/sh", "-c"]
args:
- |
if /usr/local/bin/backup.sh; then
curl -fsS -m 10 --retry 3 https://rtekfsmupinxncwigmnf.supabase.co/functions/v1/api/ping/$CRONBEAT_KEY
else
curl -fsS -m 10 --retry 3 https://rtekfsmupinxncwigmnf.supabase.co/functions/v1/api/ping/$CRONBEAT_KEY/fail
exit 1
fi
Store the key once: kubectl create secret generic cronbeat --from-literal=ping-key=YOUR_KEY. If your image has no curl, wget -q -O- URL works the same way.
What you get:
- the run is skipped, suspended or never scheduled → no ping → alert after the grace period;
- the script fails → the
/failping alerts at once; - the next run succeeds → an "UP" message.
Note: if a pod is killed before the if finishes (OOMKilled, evicted), neither ping is sent and the missed heartbeat catches it.
Choosing period and grace
Set the period to the schedule interval and give a grace time longer than your slowest normal run plus startingDeadlineSeconds. For a nightly backup that takes 20 minutes, a 1-day period with 45 minutes of grace is a sensible start. Not sure what an expression means? Use the cron explainer.
Where alerts go
Slack or Discord webhooks, or a push notification to your phone through the free ntfy app. Setup steps are in the CronBeat FAQ.
Free: 20 checks, no signup, checked every minute. Public status shows how reliably the checker itself runs.
Create a check · GitHub Actions schedules · Regular cron jobs