Creating CronJobs

CronJob provide different ways to define tasks that run to completion and then stop. You can use a CronJob to run the same Job multiple times according a schedule.

A scheduled task (CronJob) is a type of workload controller in Kubernetes. You can create a CronJob through the web console or CLI to run a non-persistent program periodically or repeatedly, such as scheduled backups, scheduled clean-ups, or scheduled email dispatches.

Prerequisites

Obtain the image address. The source of the images can be from the image repository integrated by the platform administrator through the toolchain or from third-party platforms' image repositories.

  • For the former, the Administrator typically assigns the image repository to your project, and you can use the images within it. If the required image repository is not found, please contact the Administrator for allocation.

  • If it is a third-party platform's image repository, ensure that images can be pulled directly from it in the current cluster.

Procedure

  1. Container Platform, navigate to Workloads > CronJobs in the left sidebar.

  2. Click Create CronJob.

  3. Select or Input an image, and click Confirm.

    Note: You can filter images by selecting only when using images from the integrated image repository of this platform. For example, the integrated project name such as containers (docker-registry-projectname) includes the project name projectname from this platform and the project name containers from the image repository.

Configure Basic info

  1. 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 configure the following scheduling parameters:

      ParameterDescription
      ScheduleDefine the cron schedule using Crontab syntax. The CronJob controller calculates the next execution time based on the selected time zone.

      Notes:
      • For Kubernetes clusters < v1.25: Timezone selection is unsupported; schedules MUST use UTC.
      • For Kubernetes clusters ≥ v1.25: Timezone-aware scheduling is supported (default: user's local timezone).
      Concurrency PolicySpecify how concurrent Job executions are handled (Allow, Forbid, or Replace per K8s spec).

    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.
  2. 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:

    ParameterDescription
    Job TypeSelect Job completion mode (Non-parallel, Parallel with fixed completion count, or Indexed Job per K8s Job patterns).
    Backoff LimitSet maximum retry attempts before marking a Job as failed.

Configure Pod

In the Pod section, please refer to Creating Deployment - Configure Pod

Configure Containers

In the Container section, please refer to Creating Deployment - Configure Containers

Create

Click Create.

Execute Immediately

  1. Locate the CronJob resource:

    • web console: Container Platform, navigate to Workloads > CronJob in the left sidebar.
    • CLI: Run
      kubectl get cronjobs -n <namespace>
      
  2. Initiate ad-hoc execution:

    • web console: Execute Immediately
      1. Click the vertical ellipsis (⋮) on the right side of the application list.
      2. Click Actions from the upper-right corner of the application details page.
    • CLI:
      kubectl create job --from=cronjob/<cronjob-name> <job-name> -n <namespace>
      
  3. Monitor execution status:

    StatusDescription
    PendingJob created but not yet scheduled
    RunningJob Pod(s) are actively executing
    SucceededAll Pods completed successfully (exit code 0)
    FailedAt least one Pod terminated unsuccessfully (non-zero exit code)
  4. Verify Job details:

    kubectl describe job/<job-name> -n <namespace>
    kubectl logs job/<job-name> -n <namespace>