All Products
Search
Document Center

Container Service for Kubernetes:Use ACK Serverless cluster to run jobs

Last Updated:Sep 01, 2023

In an ACK Serverless cluster, you can create pods to meet your business requirements. The system stops billing a pod after the pod lifecycle is terminated. You do not need to reserve computing resources to handle jobs. This resolves the issues of insufficient computing resources and saves you the need to expand the cluster. In addition, you can reduce the computing costs by using preemptible instances. This topic describes how to use ACK Serverless to create jobs to meet your business requirements.

Prerequisites

Procedure

  1. Use the kubectl client to create the job.yaml file and copy the following content to the file:

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: pi
    spec:
      template:
        spec:
          containers:
          - name: pi
            image: perl
            command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
            resources:
              requests:
                cpu: 16
                memory: 32Gi
          restartPolicy: Never
      backoffLimit: 4
  2. Run the following command to deploy a job:

    kubectl apply -f job.yaml
  3. Run the following commands to check the state of the pod.

    Run the following command to check the state of the pod:

    kubectl get pod

    Expected output:

    NAME       READY   STATUS      RESTARTS   AGE
    pi-4f7w5   0/1     Completed   0          80s

    Run the following command to view detailed information about the state of the pod:

    kubectl describe pod

    Expected output:

    Name:               pi-4f7w5
    Namespace:          default
    Priority:           0
    PriorityClassName:  <none>
    Node:               virtual-kubelet-cn-hongkong-b/10.10.66.169
    ...
    Events:
      Type    Reason                 Age   From          Message
      ----    ------                 ----  ----          -------
      Normal  SuccessfulMountVolume  114s  kubelet, eci  MountVolume.SetUp succeeded for volume "default-token-8k4jz"
      Normal  Pulling                113s  kubelet, eci  pulling image "perl"
      Normal  Pulled                 64s   kubelet, eci  Successfully pulled image "perl"
      Normal  Created                64s   kubelet, eci  Created container
      Normal  Started                64s   kubelet, eci  Started container
  4. Optional:To use a preemptible instance, add a preemptible instance annotation to the pod.

    For more information about how to add annotations for preemptible instances, see Use preemptible instances.

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: pi
    spec:
      template:
        metadata:
          annotations:
            k8s.aliyun.com/eci-spot-strategy: SpotAsPriceGo
        spec:
          containers:
          - name: pi
            image: perl
            command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
            resources:
              requests:
                cpu: 16
                memory: 32Gi
          restartPolicy: Never
      backoffLimit: 4