CronNudge

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

Longer guide: Kubernetes CronJobs · Overlapping cron jobs · Stuck or hanging jobs