Skip to content

Create Job

This page introduces how to create a job through image image and YAML file.

Job is suitable for performing one-time jobs. A Job creates one or more Pods, and the Job keeps retrying to run Pods until a certain number of Pods are successfully terminated. A Job ends when the specified number of Pods are successfully terminated. When a Job is deleted, all Pods created by the Job will be cleared. When a Job is paused, all active Pods in the Job are deleted until the Job is resumed. For more information about jobs, refer to Job.

Prerequisites

Create by image

Refer to the following steps to create a job using an image.

  1. Click Clusters on the left navigation bar, and then click the name of the target cluster to enter the cluster details page.

    Clusters

  2. On the cluster details page, click Workloads -> Jobs in the left navigation bar, and then click the Create by Image button in the upper right corner of the page.

    Jobs

  3. Fill in Basic Information, Container Settings and Advanced Settings in turn, click OK in the lower right corner of the page to complete the creation.

    The system will automatically return to the job list. Click on the right side of the list to perform operations such as updating, deleting, and restarting the job.

    ![Config]](../images/job07.png)

Basic information

On the Create Jobs page, enter the basic information according to the table below, and click Next .

Create Jobs

  • Payload Name: Can contain up to 63 characters, can only contain lowercase letters, numbers, and a separator ("-"), and must start and end with a lowercase letter or number. The name of the same type of workload in the same namespace cannot be repeated, and the name of the workload cannot be changed after the workload is created.
  • Namespace: Select which namespace to deploy the newly created job in, and the default namespace is used by default. If you can't find the desired namespace, you can go to Create a new namespace according to the prompt on the page.
  • Number of Instances: Enter the number of Pod instances for the workload. By default, 1 Pod instance is created.
  • Description: Enter the description information of the workload and customize the content. The number of characters should not exceed 512.

Container settings

Container setting is divided into six parts: basic information, life cycle, health check, environment variables, data storage, and security settings. Click the corresponding tab below to view the setting requirements of each part.

Container settings is only configured for a single container. To add multiple containers to a pod, click + on the right to add multiple containers.

Basic Information

When configuring container-related parameters, you must correctly fill in the container name and image parameters, otherwise you will not be able to proceed to the next step. After filling in the settings with reference to the following requirements, click OK .

  • Container Name: Up to 63 characters, lowercase letters, numbers and separators ("-") are supported. Must start and end with a lowercase letter or number, eg nginx-01.
  • Image: Enter the address or name of the image. When entering the image name, the image will be pulled from the official DockerHub by default. After accessing the container registry module of DCE 5.0, you can click Select Image on the right to select an image.
  • Image Pull Policy: After checking Always pull image , the image will be pulled from the registry every time the load restarts/upgrades. If it is not checked, only the local image will be pulled, and only when the image does not exist locally, it will be re-pulled from the container registry. For more details, refer to Image Pull Policy.
  • Privileged container: By default, the container cannot access any device on the host. After enabling the privileged container, the container can access all devices on the host and enjoy all the permissions of the running process on the host.
  • CPU/Memory Quota: Requested value (minimum resource to be used) and limit value (maximum resource allowed to be used) of CPU/Memory resource. Please configure resources for containers as needed to avoid resource waste and system failures caused by excessive container resources. The default value is shown in the figure.
  • GPU Exclusive: Configure the GPU usage for the container, only positive integers are supported. The GPU quota setting supports setting exclusive use of the entire GPU card or part of the vGPU for the container. For example, for an 8-core GPU card, enter the number 8 to let the container exclusively use the entire length of the card, and enter the number 1 to configure a 1-core vGPU for the container.

Before setting exclusive GPU, the administrator needs to install the GPU card and driver plug-in on the cluster nodes in advance, and enable the GPU feature in Cluster Settings.

Set the commands that need to be executed when the container starts, after starting, and before stopping. For details, refer to Container Lifecycle settings.

Lifecycle

It is used to judge the health status of containers and applications, which helps to improve the availability of applications. For details, refer to Container Health Check settings.

Health Check

Configure container parameters within the Pod, add environment variables or pass settings to the Pod, etc. For details, refer to Container environment variable settings.

Environment Variables

Configure the settings for container mounting data volumes and data persistence. For details, refer to Container Data Storage settings.

Data storage

Containers are securely isolated through Linux's built-in account authority isolation mechanism. You can limit container permissions by using account UIDs (digital identity tokens) with different permissions. For example, enter 0 to use the privileges of the root account.

Security settings

Advanced settings

Advanced setting includes job settings, labels and annotations.

Job Settings

  • Parallel Pods: the maximum number of Pods that can be created at the same time during job execution, and the parallel number should not be greater than the total number of Pods. Default is 1.
  • Timeout: When this time is exceeded, the job will be marked as failed to execute, and all Pods under the job will be deleted. When it is empty, it means that no timeout is set.
  • Restart Policy: Whether to restart the Pod when the setting fails.

You can click the Add button to add labels and annotations to the workload instance Pod.

Labels and Annotations

Create from YAML

In addition to image, creation jobs can also be created more quickly through YAML files.

  1. Click Clusters on the left navigation bar, and then click the name of the target cluster to enter the cluster details page.

    Clusters

  2. On the cluster details page, click Workloads -> Jobs in the left navigation bar, and then click the Create from YAML button in the upper right corner of the page.

    Create

  3. Enter or paste the YAML file prepared in advance, click OK to complete the creation.

    Confirm

Click to view the complete YAML
kind: Job
apiVersion: batch/v1
metadata:
  name: demo
  namespace: default
  uid: a9708239-0358-4aa1-87d3-a092c080836e
  resourceVersion: '92751876'
  generation: 1
  creationTimestamp: '2022-12-26T10:52:22Z'
  labels:
    app: demo
    controller-uid: a9708239-0358-4aa1-87d3-a092c080836e
    job-name: demo
  annotations:
    revisions: >-
      {"1":{"status":"running","uid":"a9708239-0358-4aa1-87d3-a092c080836e","start-time":"2022-12-26T10:52:22Z","completion-time":"0001-01-01T00:00:00Z"}}
spec:
  parallelism: 1
  backoffLimit: 6
  selector:
    matchLabels:
      controller-uid: a9708239-0358-4aa1-87d3-a092c080836e
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: demo
        controller-uid: a9708239-0358-4aa1-87d3-a092c080836e
        job-name: demo
    spec:
      containers:
        - name: container-4
          image: nginx
          resources:
            limits:
              cpu: 250m
              memory: 512Mi
            requests:
              cpu: 250m
              memory: 512Mi
          lifecycle: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: false
      restartPolicy: Never
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext: {}
      schedulerName: default-scheduler
  completionMode: NonIndexed
  suspend: false
status:
  startTime: '2022-12-26T10:52:22Z'
  active: 1

Comments