All Products
Search
Document Center

Container Service for Kubernetes:Create Jobs

Last Updated:Dec 07, 2023

You can create Jobs on Fleet instances of Distributed Cloud Container Platform for Kubernetes (ACK One) in the same way you create Jobs on individual Kubernetes clusters. After you create a Job on a Fleet instance, the Fleet instance dynamically schedules the Job to a cluster that is associated with the Fleet instance and has sufficient resources to meet the resource request of the Job. You can query the status of the Job from the Fleet instance. This topic describes how to create a Job on a Fleet instance.

Prerequisites

  • The Fleet management feature is enabled. For more information, see Enable Fleet management.

  • Multiple clusters are associated with the Fleet instance. For more information, see Associate clusters with a Fleet instance.

  • The kubeconfig file of the Fleet instance is obtained in the ACK One console and a kubectl client is connected to the Fleet instance.

  • The AMC command-line tool is installed. For more information, see Use AMC.

Procedure

  1. Use the following YAML template to create a Job on the Fleet instance.

    In this example, the job is named pi and is created in the demo namespace.

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: pi
      namespace: demo
    spec:
      parallelism: 2
      template:
        spec:
          containers:
          - name: pi1
            image: perl:5.34.0
            command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
            resources:
              requests:
                memory: "64Mi"
                cpu: "250m"
              limits:
                memory: "128Mi"
                cpu: "500m"
          restartPolicy: Never
      backoffLimit: 4
  2. Run the following command on the Fleet instance to query the scheduling result of the TensorFlow job.

    If no output is returned, the Job failed to be scheduled. In this case, check whether the specified namespace exists and whether you have a sufficient namespace quota. If the specified namespace does not exist or the namespace quota of your account is exhausted, the Job remains in the pending state.

    kubectl get job pi -n demo -o jsonpath='{.metadata.annotations.scheduling\.x-k8s\.io/placement}'
  3. Run the following command on the Fleet instance to query the status of the Job:

    kubectl get job pi -n demo

    Expected output:

    NAME   COMPLETIONS   DURATION   AGE
    pi     2/1 of 2      28s        6m20s
  4. Run the following command to query the pods that are created by the Job.

    kubectl amc get pod -j job/pi -n demo

    Expected output:

    Run on ManagedCluster managedcluster-c1xxxe5
    NAME        READY   STATUS      RESTARTS   AGE
    pi-h6z98   0/1     Completed   0          11d
    pi-xfg6r   0/1     Completed   0          11d
  5. Run the following command to print the logs of the pods that are created by the Job.

    kubectl amc logs pi1-h6z98  -j job/pi -n demo

    Expected output:

    Run on ManagedCluster managedcluster-c1xxxe5
    3.1415926...