All Products
Search
Document Center

Container Service for Kubernetes:Create a Job

Last Updated:Mar 26, 2026

A Job runs one-off tasks and ensures that a specified number of pods complete successfully. This document explains how Jobs work and how to create one in Container Service for Kubernetes (ACK) using the console or kubectl.

How Jobs work

Unlike Deployments, StatefulSets, and DaemonSets—which keep a target number of pods running continuously—a Job tracks successful pod completions. Configure spec.completions to set how many pods must complete successfully, and spec.parallelism to control how many pods run at the same time.

Execution types

Choose an execution type based on your task requirements:

Non-parallel (sequential)

Run one pod at a time. The Job is complete when the pod terminates successfully.

spec.completionsspec.parallelism
11

Use this for one-time initialization tasks, such as database migrations.

Parallel with fixed completion count

Run multiple pods in parallel, with a fixed number of required successes. The Job is complete when spec.completions pods terminate successfully.

spec.completionsspec.parallelism
NM (M ≤ N)
  • If M = N: all N pods run in parallel, all must succeed. Use this when compute resources are sufficient.

  • If M < N: N pods run in parallel, but only M successes are required. Use this when you want redundancy—for example, running tasks across multiple zones where only one result is needed.

Resource-constrained parallel

When compute resources are insufficient to run N pods in parallel, limit concurrency with spec.parallelism.

spec.completionsspec.parallelism
NM (M < N)

M pods run at a time. As each pod completes successfully, new ones start until N succeed.

Prerequisites

Before you begin, ensure that you have:

  • An ACK cluster with public network access (required to pull the sample image)

  • A kubectl connection to the cluster (required for the kubectl method only)

To enable public network access for your cluster:

Create a Job

Create a Job using the ACK console

  1. Log on to the ACK console. In the left navigation pane, click Clusters.

  2. On the Clusters page, click the name of the cluster you want. In the left-side pane, choose Workloads > Jobs.

  3. On the Jobs page, click Create from Image in the upper-left corner.

  4. In the Basic Information step, configure the basic settings, then click Next to go to the Container step.

  5. In the General section, enter registry.cn-hangzhou.aliyuncs.com/acs-sample/nginx:latest in the Image Name field. In the Start part of the Lifecycle section, enter /bin/sh in the Command field and enter ["-c", "echo 'starting...'; COUNTER=0; while [ $COUNTER -lt 5 ]; do sleep 2; COUNTER=$((COUNTER+1)); echo $COUNTER; done; echo 'finished'; exit 0"] in the Parameter field, as shown in the following figure. Then click Next to go to the Advanced step.

    Important

    Pulling the registry.cn-hangzhou.aliyuncs.com/acs-sample/nginx:latest image requires Internet access. If you kept the default value for Configure SNAT for VPC when creating the cluster, the cluster can already access the Internet. For existing clusters, see Enable an existing ACK cluster to access the Internet.

    image.png

  6. In the Advanced step, configure the Job Settings parameters. In this example, Completions is set to 2. Then click Create.

    ParameterDescription
    CompletionsThe number of pods that must terminate successfully. Corresponds to spec.completions.
    ParallelismThe number of pods that can run in parallel. Corresponds to spec.parallelism.
    TimeoutThe maximum duration for the Job, in seconds. Corresponds to spec.activeDeadlineSeconds. Default: 600. If the Job exceeds this duration, it terminates regardless of how many pods have succeeded.
    BackoffLimitThe maximum number of pod failures before the Job is marked as failed. Corresponds to spec.backoffLimit. Default: 6.
    RestartThe pod restart policy. Corresponds to template.spec.restartPolicy. Options: Never (restart the existing pod without creating a new one; does not count toward spec.backoffLimit) or On Failure (create a new pod to replace the failed one).
    Pod LabelsLabels added to each pod. ACK adds app:<application-name> by default.
    Pod AnnotationsAnnotations added to each pod. Some ACK features use annotations for configuration.

    image.png

  7. After the Job is created, view its logs in the ACK console. The two pods created by the Job produce identical output.

    image

Create a Job using kubectl

Important

Connect to the cluster using kubectl before proceeding. See Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.

  1. Create a file named job.yaml with the following content:

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: example-job
    spec:
      completions: 2      # Stop the Job after two pods terminate successfully.
      parallelism: 1      # Run only one pod at a time.
      template:
        spec:
          containers:
          - name: counter
            image: registry.cn-hangzhou.aliyuncs.com/acs-sample/nginx:latest
            command:
            - /bin/sh
            - -c
            - |
              echo "starting...";
              COUNTER=0;
              while [ $COUNTER -lt 5 ]; do
                sleep 2;
                COUNTER=$((COUNTER+1));
                echo "${COUNTER}";
              done;
              echo "finished";
              exit 0
          restartPolicy: Never
  2. Apply the manifest:

    kubectl apply -f job.yaml

    Expected output:

    job.batch/example-job created
  3. After 15 seconds, check the Job status:

    kubectl get job example-job

    The output shows one pod has succeeded and the Job is still running:

    NAME          STATUS    COMPLETIONS   DURATION   AGE
    example-job   Running   1/2           16s        16s
  4. After 40 seconds, check the Job status again:

    kubectl get job example-job

    The output shows the Job is complete:

    NAME          STATUS     COMPLETIONS   DURATION   AGE
    example-job   Complete   2/2           27s        37s
  5. View the logs from all pods:

    kubectl logs -l job-name=example-job

    Expected output (two identical sets, one from each pod):

    starting...
    1
    2
    3
    4
    5
    finished
    starting...
    1
    2
    3
    4
    5
    finished

What's next