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.
The output is similar to the following:
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-name
label injobTemplate.metadata
- You should include the resource requests for each Job Pod.
- You should set the
spec.concurrencyPolicy
to control the concurrency policy. The default isAllow
. You can also set it toForbid
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.
2. Run the CronJob
You can run the CronJob with the following command:
Internally, Kueue will create a corresponding Workload for each run of the Job with a matching name.
The output will be similar to the following:
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.