All Products
Search
Document Center

Elastic Container Instance:Run jobs on a preemptible elastic container instance

Last Updated:Jun 03, 2026

Preemptible instances run at the real-time spot price, which can significantly reduce compute costs for fault-tolerant, short-lived workloads such as batch jobs, CI/CD pipelines, and stateless web services. This topic describes how to run a Kubernetes Job on a preemptible Elastic Container Instance (ECI)-based pod.

How preemptible instances work

  • Billing

    The spot price fluctuates based on supply and demand for the instance type. When you create a preemptible instance, you specify a bid strategy. If your bid price is higher than the real-time spot price and resources are available, the instance is created. The instance then enters a protection period, during which it is billed at the spot price at the time of purchase. The protection period lasts 1 hour by default. After the protection period expires, billing switches to the real-time spot price.

  • Reclaim mechanism

    After the protection period expires, ECI checks the spot price and resource inventory every 5 minutes. If the real-time spot price exceeds your bid price or resources are insufficient, the instance is released. ECI sends a SpotToBeReleased event to the Kubernetes event list approximately 5 minutes before release. Use this window to gracefully handle the interruption — for example, you can configure to deny inbound traffic to the instance.

  • Creation methods

    You can create a preemptible instance by specifying ECS instance types or by specifying the number of vCPUs and the memory size.

  • Bid strategies

    Add the k8s.aliyun.com/eci-spot-strategy annotation to the pod metadata to set the bid strategy.

    Valid values:

    • SpotAsPriceGo: ECI automatically uses the real-time spot price as your bid.

    • SpotWithPriceLimit: You set the maximum hourly price you are willing to pay. Also add the k8s.aliyun.com/eci-spot-price-limit annotation to specify the maximum hourly price.

For more information, see Create a spot instance.

Run a job on a preemptible instance

Kubernetes Jobs batch-process short-lived, one-off tasks. The following steps show how to run a Job on a preemptible instance.

To improve instance creation success rate, specify multiple instance types in the k8s.aliyun.com/eci-use-specs annotation.

  1. Create the Job configuration file and save it as spot_job.yaml.

    apiVersion: batch/v1
    kind: Job
    metadata:
      name: pi
    spec:
      template:
        metadata:
          annotations:
            k8s.aliyun.com/eci-use-specs: ecs.c5.large,2-4Gi # Specifies multiple instance specifications to improve the success rate of instance creation.
            k8s.aliyun.com/eci-spot-strategy: SpotAsPriceGo    # The current market price is automatically used as the bid price.
        spec:
          containers:
          - name: pi
            image: registry-vpc.cn-beijing.aliyuncs.com/ostest/perl
            command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
          restartPolicy: Never
  2. Create the Job.

    kubectl create -f spot_job.yaml
  3. Check the pod status.

    kubectl get pod
    • If the Job is running, the pod status is Running.

      NAME       READY   STATUS      RESTARTS   AGE
      pi-frmr8   1/1     Running     0          35s
    • If the Job completes successfully, the pod status changes to Completed.

      NAME       READY   STATUS      RESTARTS   AGE
      pi-frmr8   0/1     Completed   0          2h
    • If the instance is reclaimed before the Job finishes, the pod status changes to BidFailed and the Job controller automatically creates a new pod to continue the Job.

      The original pod is retained in BidFailed state.

      Note

      After a preemptible instance is created, it runs as expected during the protection period. After the protection period expires, the instance is released if the real-time spot price exceeds your bid price or resources are insufficient. A pre-release event (SpotToBeReleased) is generated approximately 5 minutes before release. For more information, see Reclamation details.

      NAME       READY   STATUS      RESTARTS   AGE
      pi-frmr8   1/1     BidFailed   0          4h53m
      pi-kp5zx   1/1     Running     0          3h45m