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:

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 consider the following differences:

  • You should set the JobTemplate in CronJob in a suspended state, as Kueue will decide when it’s the best time to start the Job.
  • You have to set the Queue you want to submit the Job to. Use the label in jobTemplate.metadata
  • You should include the resource requests for each Job Pod.
  • You should set the spec.concurrencyPolicy to control the concurrency policy. The default is Allow. You can also set it to Forbid to prevent concurrent runs.
  • You should set the spec.startingDeadlineSeconds to control the deadline for starting the Job. The default is no deadline.

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

apiVersion: batch/v1
kind: CronJob
  name: sample-cronjob
  namespace: default
  schedule: "* * * * *"
      labels: user-queue
      parallelism: 3
      completions: 3
          - name: dummy-job
            args: ["10s"]
                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.