CronJobs
TOC
Understanding CronJobs
Refer to the official Kubernetes documentation:
CronJob define tasks that run to completion and then stop. They allow you to run the same Job multiple times according to a schedule.
A CronJob is a type of workload controller in Kubernetes. You can create a CronJob through the web console or CLI to periodically or repeatedly run a non-persistent program, such as scheduled backups, scheduled clean-ups, or scheduled email dispatches.
Creating CronJobs
Creating a CronJob by using CLI
Prerequisites
- Ensure you have
kubectlconfigured and connected to your cluster.
YAML file example
Creating a CronJobs via YAML
Creating CronJobs by using web console
Prerequisites
Obtain the image address. Images can be sourced from an image registry integrated by the platform administrator via a toolchain, or from third-party image registries.
-
For images from an integrated registry, the Administrator typically assigns the image registry to your project, allowing you to use the images within it. If the required image registry is not found, please contact the Administrator for allocation.
-
If using a third-party image registry, ensure that images can be pulled directly from it within the current cluster.
Procedure - Configure basic info
-
Container Platform, navigate to Workloads > CronJobs in the left sidebar.
-
Click on Create CronJob.
-
Select or Input an image, and click Confirm.
Note: Image filtering is available only when using images from the platform's integrated image registry. For example, an integrated project name like containers (docker-registry-projectname) indicates the platform's project name projectname and the image registry's project name containers.
-
In the Cron Configuration section, configure the task execution method and associated parameters.
Execute Type:
-
Manual: Manual execution requires explicit manual triggering for each task run.
-
Scheduled: Scheduled execution requires configuring the following scheduling parameters:
Job History Retention:
- Set retention limits for completed Jobs:
- History Limits: Successful jobs history limit (default: 20)
- Failed Jobs: Failed jobs history limit** (default: 20)
- When retention limits are exceeded, the oldest jobs are garbage-collected first.
-
-
In the Job Configuration section, select the job type. A CronJob manages Jobs composed of Pods. Configure the Job template based on your workload type:
Procedure - Configure Pod
- Pod section, please refer to Deployment - Configure Pod
Procedure - Configure Containers
- Container section, please refer to Deployment - Configure Containers
Create
- Click Create.
Execute Immediately
Locate the CronJob resource
- web console: Container Platform, and navigate to Workloads > CronJobs in the left sidebar.
- CLI:
Initiate ad-hoc execution
- web console: Execute Immediately
- Click the vertical ellipsis (⋮) on the right side of the cronjob list.
- Click Execute Immediately. (Alternatively, from the CronJob details page, click Actions in the upper-right corner and select Execute Immediately).
- CLI:
Verify Job details:
Monitor execution status
Deleting CronJobs
Deleting CronJobs by using web console
- Container Platform, and navigate to Workloads > CronJobs.
- Locate the CronJobs you wish to delete.
- In the Actions drop-down menu, Click the Delete button and confirm.