Monitoring Kubernetes CronJobs
Kubernetes CronJobs are scheduled workloads that run in pods. When a CronJob fails, Kubernetes may retry or simply mark it failed—but you won’t know unless you’re watching the cluster.
Configuration
Section titled “Configuration”Pass your API key as a Kubernetes secret:
env: - name: PAKYAS_API_KEY valueFrom: secretKeyRef: name: pakyas-credentials key: api-keyCreate the secret:
kubectl create secret generic pakyas-credentials --from-literal=api-key=pk_live_xxxxxOr skip the secret and ping by public ID (--public-id), which needs no API key. See Environment Variables for all options.
When to use this
Section titled “When to use this”- CronJobs run on a schedule in Kubernetes
- Missing a run affects your application
- You need alerts outside the cluster
Basic example
Section titled “Basic example”The image must contain the pakyas binary (for example RUN curl -fsSL https://pakyas.com/install.sh | PAKYAS_INSTALL_DIR=/usr/local/bin sh in the Dockerfile; see Docker). Then wrap the command with pakyas:
spec: containers: - name: job image: your-image command: ["pakyas", "monitor", "k8s-cronjob", "--", "/app/run.sh"]The pings are sent from inside the pod. If the pod never starts, no ping arrives and Pakyas alerts on the missed schedule.
Scheduler setup
Section titled “Scheduler setup”apiVersion: batch/v1kind: CronJobmetadata: name: nightly-jobspec: schedule: "0 2 * * *" jobTemplate: spec: template: spec: containers: - name: job image: your-image command: ["pakyas", "monitor", "k8s-cronjob", "--", "/app/run.sh"] env: - name: PAKYAS_API_KEY valueFrom: secretKeyRef: name: pakyas-credentials key: api-key restartPolicy: OnFailureWith only PAKYAS_API_KEY set, the CLI finds the key’s organization and looks up the slug on each run. To avoid those API calls, use command: ["pakyas", "monitor", "--public-id", "<public-id>", "--", "/app/run.sh"] and drop the secret.
What Pakyas detects
Section titled “What Pakyas detects”- Job container exits non-zero
- Job runs longer than expected
- Job never runs (missed schedule)