All Products
Search
Document Center

Container Compute Service:Create a Job

Last Updated:Dec 30, 2024

A Job processes multiple short-lived, one-off tasks at a time to ensure that one or more pods in the tasks terminate with success. You can use a Job to create an application in the Alibaba Cloud Container Compute Service (ACS) console. This topic describes how to create a Job.

Background information

Jobs are classified into the following types based on the .spec.completions and .spec.parallelism parameters. The .spec.completions parameter specifies the number of pods that terminate with success before the Job is considered completed. Default value: 1. The .spec.parallelism parameter specifies the number of pods that the Job must run in parallel. Default value: 1.

Job type

completions

parallelism

Example

Action

One-off Job

1

1

Database migration

The Job starts only one pod. The Job is completed when the pod terminates with success.

Job with a fixed completion count

2+

1

Start pods one after one to process a work queue

The Job starts pods one by one. The Job is completed when the number of pods that terminate with success reaches the value of .spec.completions.

Parallel Job with a work queue

1

2+

A Job of this type starts multiple pods at a time.

The Job runs multiple pods in parallel and is considered completed when all pods terminate and at least one pod terminates with success.

Parallel Job with a fixed completion count

2+

2+

A Job of this type starts multiple pods at a time.

The Job runs multiple pods in parallel and is considered completed when the number of pods that terminate with success reaches the value of .spec.completions.

Procedure

Step 1: Configure basic application settings

  1. Log on to the ACS console. In the left-side navigation pane, click Clusters.

  2. On the Clusters page, find the cluster that you want to manage and click its ID or click Details in the Actions column of the cluster.

  3. In the left-side navigation pane of the details page, choose Workloads > Jobs.

  4. On the Jobs page, click Create from Image.

  5. On the Basic Information wizard page, configure the basic settings of the application.

    Parameter

    Description

    Name

    Enter a name for the application.

    Type

    Select Job.

    Label

    Add labels to the application. The labels are used to identify the application.

    Annotations

    Add annotations to the application.

    Instance Type

    The instance type that you want to use. For more information, see ACS pod overview.

    QoS Type

    Select a QoS class. For more information, see Computing power QoS.

    • General-purpose pods support the Default and BestEffort QoS classes.

    • Performance-enhanced pods support only the Default QoS class.

  6. After you complete the basic settings, click Next.

Step 2: Configure container settings

On the Container wizard page, configure the container image, resource configurations, ports, environment variables, lifecycle, volumes, and logs.

Note

Click Add Container to the right of the Container1 tab to add more containers.

  1. In the General section, configure the basic container settings.

    Parameter

    Description

    Image Name

    • Select Image

      Click Select images and select a container image.

      • Container Registry Enterprise Edition: Select an image stored on a Container Registry Enterprise Edition instance. You must select the region and the Container Registry instance to which the image belongs. For more information about Container Registry, see What is Container Registry?

      • Container Registry Personal Edition: Select an image stored on a Container Registry Personal Edition instance. Make sure that Container Registry Personal Edition is activated. You must select the region and the Container Registry instance to which the image belongs.

      • Artifact Center: The artifact center contains base operating system images, base language images, and AI- and big data-related images for application containerization. In this example, an NGINX image is selected. For more information, see Overview of the artifact center.

    • (Optional ) Set the image pulling policy

      Select an image pulling policy from the Image Pull Policy drop-down list. By default, the Kubernetes IfNotPresent policy is used.

      • ifNotPresent: If the image that you want to pull is found on your on-premises machine, the image on your on-premises machine is used. Otherwise, the system pulls the image from the image registry.

      • Always: The system pulls the image from the registry each time the application is deployed or expanded.

      • Never: The system uses only images on your on-premises machine.

    • (Optional) Set the image pull secret

      Click Set Image Pull Secret to set a Secret used to pull the private image.

    Required Resources

    Specify the resource requests of the container.

    • CPU: You can configure the CPU request and CPU limit of the container. By default, the CPU request equals the CPU limit. CPU resources are billed on a pay-as-you-go basis. If you use a YAML template to set a resource limit that differs from the resource request, the resource request is automatically overridden to the value of the resource limit. For more information, see Resource specifications.

    • Memory: You can configure the memory request and memory limit of the container. By default, the memory request equals the memory limit. Memory resources are billed on a pay-as-you-go basis. If you use a YAML template to set a resource limit that differs from the resource request, the resource request is automatically overridden to the value of the resource limit. For more information, see Resource specifications.

    Container Start Parameter

    Specify the startup options of the container. This parameter is optional.

    • stdin: passes input in the ACK console to the container.

    • tty: passes start parameters that are defined in a virtual terminal to the ACK console.

    Note

    stdin and tty are used together. In this case, the virtual terminal (tty) is associated with the stdin of the container. For example, an interactive program receives the stdin from the user and displays the content in the terminal.

    Init Containers

    If you select this check box, an init container is created. This parameter is optional.

    Init containers can be used to block or postpone the startup of application containers. Application containers in a pod concurrently start only after init containers start. For example, you can use init containers to verify the availability of a service on which the application depends. You can run tools or scripts that are not provided by an application image in init containers to initialize the runtime environment for application containers. For example, you can run tools or scripts to configure kernel parameters or generate configuration files. For more information, see Init Containers.

  2. Optional: In the Ports section, you can click Add to add container ports.

    Parameter

    Description

    Name

    Enter a name for the container port.

    Container Port

    Specify the container port that you want to expose. The port number must be in the range of 1 to 65535.

    Protocol

    Valid values: TCP and UDP.

  3. Optional: In the Environments section, you can click Add to add environment variables.

    You can add environment variables in key-value pairs to a pod in order to add environment labels or pass configurations. For more information, see Expose Pod Information to Containers Through Environment Variables.

    Parameter

    Description

    Type

    Select the type of environment variable. Valid values:

    • Custom

    • Parameter

    • Secrets

    • Value/ValueFrom

    • ResourceFieldRef

    If you select ConfigMaps or Secrets, you can pass all data in the selected ConfigMap or Secret to the container environment variables.

    In this example, Secrets is selected. Select Secrets from the Type drop-down list and select a Secret from the Value/ValueFrom drop-down list. By default, all data in the selected Secret is passed to the environment variable. 环境变量

    In this case, the YAML file that is used to deploy the application contains the settings that reference all data in the selected Secret. yaml

    Variable Key

    The name of the environment variable.

    Value/ValueFrom

    The value of the environment variable.

  4. Optional: In the Lifecycle section, you can configure the lifecycle of the container.

    You can specify the following parameters to configure the lifecycle of the container: Start, Post Start, and Pre Stop. For more information, see Attach Handlers to Container Lifecycle Events.

    Parameter

    Description

    Start

    Specify a command and parameter that takes effect before the container starts.

    Post Start

    Specify a command that takes effect after the container starts.

    Pre Stop

    Specify a command that terminates the container.

  5. Optional: In the Volume section, configure volumes that you want to mount to the container.

    • Local storage: You can select ConfigMap, Secret, or EmptyDir from the PV Type drop-down list. Then, set the Mount Source and Container Path parameters to mount the volume to a container path. For more information, see Volumes.

    • Cloud storage: Disks and File Storage NAS (NAS) file systems are supported. For more information, see Storage overview.

  6. Optional: In the Log section, you can specify logging configurations and add custom tags to the collected log.

    Parameter

    Description

    Collection Configuration

    • Logstore: Create a Logstore in Log Service to store the collected log data.

    • Log Path in Container (Can be set to stdout): specifies stdout or a path to collect the log.

      • Collect stdout files: If you specify stdout, the stdout files are collected.

      • Text Logs: specifies that the logs in the specified path of the container are collected. In this example, /var/log/nginx is specified as the path. Wildcard characters can be used in the path.

    Custom Tag

    You can also add custom tags. The tags are added to the log of the container when the log is collected. You can add custom tags to container logs for log analysis and filtering.

  7. Click Next to go to the Advanced wizard page.

Step 3: Configure advanced settings

  1. In the Job Settings section, Configure the Job parameters.

    Parameter

    Description

    Completions

    The number of pods that must terminate with success. Default value: 1.

    Parallelism

    The number of pods that the Job must run in parallel. Default value: 1.

    Timeout

    The activeDeadlineSeconds field in the YAML file. This field specifies the duration time limit of the Job. If the Job is not complete within the duration time limit, the system attempts to terminate the Job.

    BackoffLimit

    The maximum number of attempts to recreate pods after pods fail. Default value: 6. Failed pods are recreated with an exponential back-off delay. The upper limit of the delay is 6 minutes.

    Restart

    Valid values: Never and On Failure.

  2. Optional: In the Labels,Annotations section, click Add to add labels and annotations to the pod.

  3. Click Create Now.

Step 4: View application information

After the application is created, click View Details on the page that appears to go to the details page of the Job.

You can also view the information on the Jobs page. Click the name of the Job or click Details in the Actions column of the Job to go to the details page.