All Products
Search
Document Center

Container Service for Kubernetes:Colocate ECS instances and elastic container instances in Knative

Last Updated:Mar 25, 2026

Run baseline Knative workloads on existing Elastic Compute Service (ECS) instances and automatically overflow traffic spikes to elastic container instances (ECI) — without pre-provisioning extra VMs. A ResourcePolicy controls the scheduling priority between the two resource types: ECS is preferred at steady state, and ECI absorbs the overflow. During scale-in, ECI instances are released first.

Prerequisites

Before you begin, ensure that you have:

Limitations

ConstraintDetails
Mutually exclusive with pod deletion costCannot use priority-based resource scheduling together with the pod deletion cost feature.
Mutually exclusive with ECI-based schedulingCannot use priority-based resource scheduling together with Elastic Container Instance-based scheduling.
Scale-in is best-effortThe ResourcePolicy uses the prefer strategy (BestEffort). Scale-in does not guarantee that pods are removed in strict priority order.
max parameter requires Kubernetes 1.22+ and scheduler 5.0+The max parameter is only available when your cluster runs Kubernetes 1.22 or later and your scheduler version is 5.0 or later.
Elastic node pools must be in units without maxWhen using elastic node pools, include them in units but do not specify the max parameter for those units.
Pre-existing pods (scheduler < 5.0 or Kubernetes 1.20 or earlier)Pods that existed before the ResourcePolicy was created are prioritized during scale-in.
ResourcePolicy modification (scheduler < 6.1 or Kubernetes 1.20 or earlier)Do not modify the ResourcePolicy until all pods selected by it are deleted.

Create a ResourcePolicy for hybrid ECS and ECI scheduling

A ResourcePolicy targets a Knative Service by label and defines an ordered list of units. Each unit maps to a resource type (ECS or ECI) and can optionally cap the number of pods with max. The scheduler works through the units in order: when an ECS unit is full or no ECS capacity is available, pods overflow to the next unit.

  1. Create a Knative Service.

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: helloworld-go
    spec:
      template:
        spec:
          containers:
          - image: registry-vpc.cn-beijing.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
            env:
            - name: TARGET
              value: "Knative"
  2. Create a ResourcePolicy that targets the helloworld-go Knative Service. ECS instances have the highest priority. ECI is the fallback — pods are scheduled to ECI only when ECS capacity is exhausted or when the number of pods on an ECS unit reaches the max limit.

    apiVersion: scheduling.alibabacloud.com/v1alpha1
    kind: ResourcePolicy
    metadata:
      name: xxx
      namespace: xxx
    spec:
      selector:
        serving.knative.dev/service: helloworld-go  # Target Knative Service name
      strategy: prefer
      units:
      - resource: ecs
        max: 10           # Cap at 10 pods on this ECS node group
        nodeSelector:
          key2: value2
      - resource: ecs     # Secondary ECS node group (no cap)
        nodeSelector:
          key3: value3
      - resource: eci     # ECI absorbs overflow; released first during scale-in

    Scale-in follows the reverse unit order on a best-effort basis — ECI instances are preferably released first, but strict ordering is not guaranteed.

Next steps

For more details on priority-based resource scheduling parameters, see Configure priority-based resource scheduling.