Jobs

更新时间:
复制 MD 格式

Jobs handle batch processing for one-off tasks that run only once. A Job ensures that one or more of its pods complete successfully. This topic describes how to create Jobs and perform other common operations in the console.

Note

Jobs are a native Kubernetes concept. For more information, see the official Kubernetes documentation.

Create a Job

  1. Log on to the LHC console. In the navigation pane on the left, click Cluster Management > Clusters Details to go to the cluster list page.

  2. Click the name of the destination cluster. On the Cluster Details page, click the Workloads tab.

  3. In the left-side menu, choose Jobs. Then, click Create Job.

  4. In the dialog box that appears, enter the YAML content and click Submit.

    The following is a YAML example:

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: hello
    spec:
      template:
        spec:
          containers:
            - name: hello
              image: 'registry-vpc.cn-hangzhou.aliyuncs.com/sofa-samples/nginx:latest'
              command:
                - /bin/sh
                - '-c'
                - date; echo Hello from the Kubernetes cluster
          restartPolicy: Never
      backoffLimit: 1

    The following table describes the parameters.

    Parameter

    Description

    kind

    Identifies the resource type as a Job.

    metadata

    Basic information about the Job, such as its name.

    spec.Template

    The detailed template configuration for the pods that the Job manages.

    restartPolicy

    Specifies the restart policy for the job. Valid values are Never and OnFailure.

    • Never: The pod is not restarted if a container fails.

    • OnFailure: The task is re-executed if it fails.

    backoffLimit

    The number of times a failed Job is retried.

Result

After the Job is created, a Job named hello appears in the list.

Related operations

  • To view the details of a Job, click its name on the Jobs page. On the details page, you can view basic information, the pod list, events, and the YAML configuration.

  • To search for a Job, enter a keyword from its name in the search box in the upper-right corner of the Jobs page.

  • To update a Job, click View/Edit in the Actions column on the Jobs page. In the Edit Job dialog box, edit the YAML information and then click Submit.

  • To delete a Job, click the more icon and then click Delete in the Actions column on the Jobs page. In the dialog box that appears, click OK.