Jobs

    A simple case is to create one Job object in order to reliably run one Pod to completion. The Job object will start a new Pod if the first Pod fails or is deleted (for example, due to a node hardware failure or a node reboot). You can also use a Job to run multiple Pods in parallel.

    The following example demonstrates specific steps of creating a Job (computing π to 2000 decimal places) on KubeSphere.

    You need to create a workspace, a project and a user (). The user must be invited to the project with the role of operator. For more information, see Create Workspaces, Projects, Users and Roles.

    Log in to the console as project-regular. Go to Jobs under Application Workloads and click Create.

    Step 2: Enter basic information

    Enter the basic information. Refer to the image below as an example.

    • Name: The name of the Job, which is also the unique identifier.
    • Alias: The alias name of the Job, making resources easier to identify.
    • Description: The description of the Job, which gives a brief introduction of the Job.

    Step 3: Strategy settings (optional)

    You can set the values in this step or click Next to use the default values. Refer to the table below for detailed explanations of each field.

    Step 4: Set a Pod

    1. Select Re-create Pod for Restart Policy. You can only specify Re-create Pod or Restart container for Restart Policy when the Job is not completed:

      • If Restart Policy is set to Re-create Pod, the Job creates a new Pod when the Pod fails, and the failed Pod does not disappear.

      • If Restart Policy is set to Restart container, the Job will internally restart the container when the Pod fails, instead of creating a new Pod.

    2. On the same page, scroll down to Start Command. Enter the following commands in the box which computes pi to 2000 places then prints it. Click in the lower-right corner and select Next to continue.

      Note

      For more information about setting images, see Pod Settings.

    1. Enable Edit YAML in the upper-right corner which displays the manifest file of the Job. You can see all the values are set based on what you have specified in the previous steps.

      1. kind: Job
      2. metadata:
      3. namespace: demo-project
      4. labels:
      5. name: job-test-1
      6. annotations:
      7. kubesphere.io/alias-name: Test
      8. kubesphere.io/description: A job test
      9. spec:
      10. template:
      11. metadata:
      12. labels:
      13. app: job-test-1
      14. spec:
      15. containers:
      16. - name: container-4rwiyb
      17. imagePullPolicy: IfNotPresent
      18. image: perl
      19. - perl
      20. - '-Mbignum=bpi'
      21. - '-wle'
      22. - print bpi(2000)
      23. serviceAccount: default
      24. initContainers: []
      25. volumes: []
      26. imagePullSecrets: null
      27. backoffLimit: 5
      28. completions: 4
      29. parallelism: 2
      30. activeDeadlineSeconds: 300
    2. You can make adjustments in the manifest directly and click Create or disable the Edit YAML and get back to the Create page.

      Note

      You can skip Volume Settings and Advanced Settings for this tutorial. For more information, see and Configure advanced settings.

    Step 6: Check the result

    1. In the final step of Advanced Settings, click Create to finish. A new item will be added to the Job list if the creation is successful.

    2. Click this Job and go to Job Records where you can see the information of each execution record. There are four completed Pods since Completions was set to 4 in Step 3.

      You can rerun the Job if it fails and the reason for failure is displayed under Message.

    3. In Resource Status, you can inspect the Pod status. Two Pods were created each time as Parallel Pods was set to 2. Click on the right and click Jobs - 图2 to check the container log, which displays the expected calculation result.

      Tip

      • In Resource Status, the Pod list provides the Pod’s detailed information (for example, creation time, node, Pod IP and monitoring data).
      • You can view the container information by clicking the Pod.
      • Click the container log icon to view the output logs of the container.
      • You can view the Pod details page by clicking the Pod name.

    Operations

    On the Job details page, you can manage the Job after it is created.

    • Edit Information: Edit the basic information except of the Job.
    • Rerun: Rerun the Job, the Pod will restart, and a new execution record will be generated.
    • View YAML: View the Job’s specification in YAML format.
    • Delete: Delete the Job and return to the Job list page.

    Execution records

    1. Click the Job Records tab to view the execution records of the Job.

    2. Click to refresh the execution records.

    1. Click the Resource Status tab to view the Pods of the Job.

    2. Click Jobs - 图4 to refresh the Pod information, and click /Jobs - 图6 to display/hide the containers in each Pod.

    Metadata

    Click the Metadata tab to view the labels and annotations of the Job.

    Environment variables

    Events

    Click the Events tab to view the events of the Job.