Run A CronJob
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:
- A Kubernetes cluster is running.
 - The kubectl command-line tool has communication with your cluster.
 - Kueue is installed.
 - The cluster has quotas configured.
 
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 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
kueue.x-k8s.io/queue-namelabel injobTemplate.metadata - You should include the resource requests for each Job Pod.
 - You should set the 
spec.concurrencyPolicyto control the concurrency policy. The default isAllow. You can also set it toForbidto prevent concurrent runs. - You should set the 
spec.startingDeadlineSecondsto 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
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: Never2. 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.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.