Kubernetes CronJob
Keep the ping URL in a secret. The container curls /start, runs the task, then curls success or /fail.
apiVersion: batch/v1
kind: CronJob
metadata:
name: backup
spec:
schedule: "0 3 * * *"
jobTemplate:
spec:
template:
spec:
restartPolicy: Never
containers:
- name: backup
image: backup:latest
env:
- name: CRONNUDGE_URL
valueFrom:
secretKeyRef:
name: cronnudge
key: url
command: ["/bin/sh", "-c"]
args:
- |
curl -fsS -m 10 "$CRONNUDGE_URL/start"
if /backup.sh; then
curl -fsS -m 10 "$CRONNUDGE_URL"
else
curl -fsS -m 10 "$CRONNUDGE_URL/fail"
exit 1
fi- concurrencyPolicy and startingDeadlineSeconds are yours to choose. CronNudge only sees the pings.
- A job that never starts, because the cluster is unhappy, produces no ping and then a late alert.
- The badge URL is a different key. You can put the badge in a README without exposing the ping URL.
Longer guide: Kubernetes CronJobs · Overlapping cron jobs · Stuck or hanging jobs