• Cloud Container Engine

cce
  1. Help Center
  2. Cloud Container Engine
  3. User Guide 2.0
  4. Job Management
  5. Creating a One-off Jobs

Creating a One-off Jobs

A one-off job is executed only once immediately after being deployed. Before creating an application, you can execute a one-off job to upload an image or software package to the software repository.

Prerequisites

Nodes have been added. For more information, see Creating a Node in a VM Cluster.

Procedure

  1. (Optional) If you use a private container image to create your one-off job, upload the container image to the image repository.

    For details about how to use the image repository, see Image Repository.

  2. Log in to the CCE console, choose Job Management > One-off Jobs, and click Create Job.
  3. Configure the basic job information listed in Table 1. The parameters marked with an asterisk (*) are mandatory.

    Table 1 Basic job information

    Parameter

    Description

    * Job Name

    Name of a new job. The name must be unique.

    * Cluster

    Cluster to which a new job belongs.

    * Namespace

    Namespace to which a job belongs.

    Description

    Description of a job.

  4. Click Next to add a container.

    1. Click Select Container Image and select the image to be deployed.
      • The My Images tab page displays all images you created.
      • Third-party Images: CCE allows you to create an application using an image pulled from a third-party image repository, rather than a public cloud image repository or a Docker Hub image repository. When you create an application using a third-party image, ensure that the node where the application is running can access public networks. For details about how to create an application using a third-party image, see Using a Third-party Image to Create an Application.
        • If your image repository does not require authentication, set Authenticate Secret to No, specify Image Address, for example, nginx:latest, and click OK.
        • If your image repository is accessible only after being authenticated by account and password, set Authenticate Secret to Yes. You need to create a secret first and then user a third-party image to create an application.
    2. Set image parameters.
      Table 2 Image parameters

      Parameter

      Description

      Image

      Image to be imported. You can click Change Image to change your image.

      * Image Version

      Image version to be deployed.

      * Container Name

      Name of the container. You can modify this parameter.

      Container Resources

      • Request: the amount of resources that CCE will guarantee to a container.
      • Limit: the maximum amount of resources that CCE will allow a container to use. You can set Limit to prevent system faults caused by container overload.

      For more information on Request and Limit, see section Setting Container Specifications.

    3. (Optional) Configure advanced settings.
      Table 3 Advanced settings

      Parameter

      Description

      Environment Variables

      Environment variables are set in the container running environment and can be modified after job deployment to ensure the flexibility of jobs.
      1. On the Environment Variables tab page, click Add.
      2. Set Variable Name and Variable/Variable Reference.

      Data Storage

      You can mount a host directory, EVS disk, SFS, and configuration items and secrets to the corresponding directories of a container instance. For details, see Storage Management.

      Log Policies

      Set a log policy and log path for collecting application logs and preventing logs from being over-sized. For details, see Log Management.

    4. (Optional) One job instance contains one or more related containers. If your job contains multiple containers, click Add Container and then add containers.

  5. Click Create Now.

    If the status is Execution completed, the job has been created successfully.

Creating a Job Using kubectl

A job has the following configuration parameters:

  • spec.template: has exactly the same schema as a pod.
  • RestartPolicy: can only be set to Never or OnFailure.
  • For a single-pod job, the job ends after the pod runs successfully by default.
  • .spec.completions: indicates the number of pods that need to run successfully to end a job. The default value is 1.
  • .spec.parallelism: indicates the number of pods that run concurrently. The default value is 1.
  • spec.backoffLimit: indicates the maximum number of retries performed if a pod fails. When the limit is reached, the pod will not try again.
  • .spec.activeDeadlineSeconds: indicates the running time of pods. Once the time is reached, all pods of the job are terminated. The priority of .spec.activeDeadlineSeconds is higher than that of .spec.backoffLimit. That is, if a job reaches the .spec.activeDeadlineSeconds, the spec.backoffLimit is ignored.

Based on the .spec.completions and .spec.Parallelism settings, jobs are classified into the following types.

Table 4 Job types

Job Type

Description

Example

One-shot jobs

A single pod runs once until successful termination.

Database migration

Jobs with a fixed completion count

One pod runs until reaching the specified completions count.

Work queue processing pod

Parallel jobs with a fixed completion count

Multiple pods run until reaching the specified completions count.

Multiple pods processing from a centralized work queue

Parallel jobs

One or more pods run until successful termination.

Multiple pods processing from a centralized work queue

The following is an example job, which calculates π till the 2000th digit and prints the output.

apiVersion: batch/v1
kind: Job
metadata:
  name: pi-with-timeout
spec:
   completions: 50                  # Indicates that 50 pods need to run to end the job. In this example, the value of π is printed 50 times.
   parallelism: 5                   # Indicates 5 parallel pods.
   backoffLimit: 5                  # Indicates that a pod that fails retries a maximum of 5 times.
   template:
     spec:
       containers:
       - name: pi
         image: perl
         command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
       restartPolicy: Never

Related Operations

After a one-off job is created, you can perform operations listed in Table 5.

Table 5 Other operations

Operation

Description

Deleting a one-off job

  1. Select the job to be deleted and click Delete in the Operation column.
  2. Click OK.

    Deleted jobs cannot be restored. Therefore, exercise caution when deleting a job.