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_xxxxxSee 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”Update your CronJob spec to wrap the command with pakyas:
spec: containers: - name: job image: your-image command: ["pakyas", "monitor", "k8s-cronjob", "--", "/app/run.sh"]Pakyas sends pings from inside the pod, so you get alerts even if the cluster itself has issues.
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"] restartPolicy: OnFailureWhat Pakyas detects
Section titled “What Pakyas detects”- Job container exits non-zero
- Job runs longer than expected
- Job never runs (missed schedule)