Updated on 2023-07-07 GMT+08:00

Creating a Job

Job Overview

In Kubernetes, there are two types of jobs: one-off jobs and cron jobs.

A job (one-off job) is a resource object that Kubernetes uses to control batch tasks. Jobs are different from long-term servo tasks (such as Deployments and StatefulSets). The former are started and terminated at specific times, while the latter run unceasingly unless being terminated. The pods managed by a job automatically exit after successfully completing the job based on user configurations. The success flag varies depending on the spec.completions policy. A single-pod job is considered successful if one pod completes successfully. A job with a fixed success count is considered successful if N pods complete successfully. A queue job is considered successful based on the global success confirmed by the application.

Similar to the Cron tab in Linux OS, a cron job can:

  • Run a scheduled job once at the specified time.
  • Run a scheduled job periodically at the specified time.

The typical usage of a cron job is as follows:

  • Schedules jobs at the specified time.
  • Creates jobs to run periodically, for example, database backup and email sending.

Creating a Job

A job runs pods that perform a completable task. The pods automatically exit after successfully completing the task. Before creating a workload, you can run a job to upload an image to the image repository.

  1. (Optional) If you use a private container image to create your job, upload the container image to the image repository.
  2. Log in to the cluster console. In the navigation pane, choose Workloads > Jobs. On the page displayed, click Create Job.
  3. Configure parameters as prompted. For details, see Creating a Job.
  4. After the job is created, you can view the job in the job list.

    If the status of the job is Executing, the job has been created successfully.

Creating a Cron Job

A cron job can run a scheduled job once or periodically at the specified time. The job automatically exits after successfully completing the task. For example, you can perform time synchronization for all active nodes at the specified time.

  1. (Optional) If you use a private container image to create your cron job, upload the container image to the image repository.
  2. Log in to the cluster console. In the navigation pane, choose Workloads > Cron Jobs. On the page displayed, click Create Cron Job.
  3. Configure parameters as prompted. For details, see Creating a Cron Job.
  4. After the cron job is created, you can view the cron job in the cron job list.

    If the status is Started, the cron job has been created successfully.