Run A CronJob

Run a CronJob in a Kubernetes cluster with Kueue enabled.

This page shows you how to run a CronJob in a Kubernetes cluster with Kueue enabled.

The intended audience for this page are batch users.

Before you begin

Make sure the following conditions are met:

0. Identify the queues available in your namespace

Run the following command to list the LocalQueues available in your namespace.

kubectl -n default get localqueues
# Or use the 'queues' alias.
kubectl -n default get queues

The output is similar to the following:

NAME         CLUSTERQUEUE    PENDING WORKLOADS
user-queue   cluster-queue   3

The ClusterQueue defines the quotas for the Queue.

1. Define the Job

Running a CronJob in Kueue is similar to running a CronJob in a Kubernetes cluster without Kueue. However, you must set the kueue.x-k8s.io/queue-name label in jobTemplate.metadata selecting the LocalQueue you want to submit the Job to. You can also skip setting the “queue name” label if you use LocalQueue defaulting.

You should also:

Note that you do not need to set the JobTemplate in CronJob in a suspended state. Kueue automatically manages the Job’s suspension via webhook and decides when it’s the best time to start the Job.

Here is a sample CronJob with three Pods that just sleep for 10 seconds. The CronJob runs every minute.

apiVersion: batch/v1
kind: CronJob
metadata:
  name: sample-cronjob
  namespace: default
spec:
  schedule: "* * * * *"
  jobTemplate:
    metadata:
      labels:
        kueue.x-k8s.io/queue-name: user-queue
    spec:
      parallelism: 3
      completions: 3
      template:
        spec:
          containers:
          - name: dummy-job
            image: registry.k8s.io/e2e-test-images/agnhost:2.53
            args: ["entrypoint-tester", "hello", "world"]
            resources:
              requests:
                cpu: 1
                memory: "200Mi"
          restartPolicy: Never

2. Run the CronJob

You can run the CronJob with the following command:

kubectl create -f sample-cronjob.yaml

Internally, Kueue will create a corresponding Workload for each run of the Job with a matching name.

kubectl -n default get workloads

The output will be similar to the following:

NAME                                QUEUE        ADMITTED BY     AGE
job-sample-cronjob-28373362-0133d   user-queue   cluster-queue   69m
job-sample-cronjob-28373363-e2aa0   user-queue   cluster-queue   68m
job-sample-cronjob-28373364-b42ac   user-queue   cluster-queue   67m

You can also Monitoring Status of the Workload.