Kubernetes CronJob
Keep the ping URL in a Secret and wrap the container's command. Give the check the same schedule and time zone as the CronJob.
apiVersion: v1
kind: Secret
metadata:
name: backup-ping
stringData:
url: https://staging.crony.sh/ping/f3a1c6e2-8d4b-4c7a-9e15-2b6d0c9a7f31
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: backup
spec:
schedule: "30 2 * * *"
timeZone: "Etc/UTC"
concurrencyPolicy: Forbid
jobTemplate:
spec:
backoffLimit: 0
template:
spec:
restartPolicy: Never
containers:
- name: backup
image: backup-image
env:
- name: PING_URL
valueFrom:
secretKeyRef:
name: backup-ping
key: url
command: ["sh", "-c"]
args:
- |
curl -fsS -m 10 --retry 5 -o /dev/null "$PING_URL/start"
/app/backup; status=$?
curl -fsS -m 10 --retry 5 -o /dev/null "$PING_URL/$status"
exit $statusIf the cluster never starts the pod, no ping arrives and the check goes down when its grace time runs out. If several runs can overlap, add a run ID.