cronping

Kubernetes CronJobs

Monitor Kubernetes CronJobs with Cronping.

Add a Cronping URL as a Kubernetes Secret, then call it from the CronJob container after the job completes.

Secret

apiVersion: v1
kind: Secret
metadata:
  name: cronping-secrets
  namespace: production
type: Opaque
stringData:
  backup-url: "https://ping.cronping.com/YOUR_TOKEN"

Basic CronJob

apiVersion: batch/v1
kind: CronJob
metadata:
  name: database-backup
  namespace: production
spec:
  schedule: "0 2 * * *"
  timeZone: "UTC"
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 3
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: Never
          containers:
            - name: backup
              image: postgres:16
              env:
                - name: DATABASE_URL
                  valueFrom:
                    secretKeyRef:
                      name: database-secrets
                      key: url
                - name: CRONPING_URL
                  valueFrom:
                    secretKeyRef:
                      name: cronping-secrets
                      key: backup-url
              command:
                - /bin/sh
                - -c
                - |
                  pg_dump "$DATABASE_URL" | gzip > /tmp/backup.sql.gz
                  EXIT_CODE=$?
                  curl -fsS --retry 3 --max-time 10 "$CRONPING_URL/$EXIT_CODE"
                  exit $EXIT_CODE

Track long-running jobs

command:
  - /bin/sh
  - -c
  - |
    curl -fsS --retry 3 --max-time 10 "$CRONPING_URL/start"
    ./run-etl.sh > /tmp/etl.log 2>&1
    EXIT_CODE=$?
    curl -fsS --retry 3 --max-time 10 \
      -X POST "$CRONPING_URL/$EXIT_CODE" \
      -H "Content-Type: text/plain" \
      --data-binary @/tmp/etl.log
    exit $EXIT_CODE

Schedule matching

Set the Cronping heartbeat to the same cron expression and timezone as the Kubernetes CronJob.

If your cluster version does not support spec.timeZone, Kubernetes uses the timezone of the controller manager. Prefer explicit UTC schedules when possible.

On this page