Skip to content

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.

Pass your API key as a Kubernetes secret:

env:
- name: PAKYAS_API_KEY
valueFrom:
secretKeyRef:
name: pakyas-credentials
key: api-key

Create the secret:

Terminal window
kubectl create secret generic pakyas-credentials --from-literal=api-key=pk_live_xxxxx

Or skip the secret and ping by public ID (--public-id), which needs no API key. See Environment Variables for all options.

  • CronJobs run on a schedule in Kubernetes
  • Missing a run affects your application
  • You need alerts outside the cluster

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.

apiVersion: batch/v1
kind: CronJob
metadata:
name: nightly-job
spec:
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: OnFailure

With 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.

  • Job container exits non-zero
  • Job runs longer than expected
  • Job never runs (missed schedule)