Configure Knative reserved instances

更新时间:
复制 MD 格式

For slow-starting applications such as Java apps, community Knative's default scale-to-zero policy can cause high cold-start latency. ACK provides reserved instances that keep low-cost warm instances running during idle periods to respond quickly while controlling cost.

How it works

By default, Knative scales a Service to zero pods when traffic stops. A new request must wait for resource scheduling, image pulling, and application startup — which can take several seconds.

With a reserved instance enabled, this behavior changes:

  1. Traffic stops — The Knative Service scales in, but one reserved instance stays online.

  2. First request arrives — Two actions happen simultaneously:

    • The reserved instance handles the request immediately.

    • Knative creates standard instances to take over ongoing traffic.

  3. Traffic handover — Once a standard instance is ready, subsequent requests are routed to it.

  4. Cleanup — After handling the initial request, the reserved instance is terminated.

image

Prerequisites

Before you begin, ensure that you have:

Enable reserved instances

Add these annotations to your Knative Service manifest:

Annotation

Description

knative.aliyun.com/reserve-instance: "enable"

Enables reserved instances

knative.aliyun.com/reserve-instance-type: <type>

The instance type. Valid values: eci (default), ecs, acs

Reserved instances incur charges continuously, even with no traffic. See Billing.

Choose an instance type

Select the instance type for your workload:

Instance type

Best for

Requires

ECI (default)

General-purpose serverless workloads; no node management needed

ACK Virtual Node

ACS

Workloads requiring fine-grained compute class and quality tier control

ACK Virtual Node

ECS

GPU workloads or those requiring a specific ECS instance type

A compatible ECS node

If unsure, start with ECI — it covers most scenarios and requires only ACK Virtual Node.

Configure ECI reserved instances

Elastic Container Instance (ECI) is the default type. Use the knative.aliyun.com/reserve-instance-eci-use-specs annotation to specify resources — by instance type or by CPU and memory.

Specify by instance type

This example uses ecs.t6-c1m1.large and ecs.t5-lc1m2.small as candidate instance types:

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: hello-spec-1
spec:
  template:
    metadata:
      annotations:
        knative.aliyun.com/reserve-instance: enable
        knative.aliyun.com/reserve-instance-eci-use-specs: "ecs.t6-c1m1.large,ecs.t5-lc1m2.small"
    spec:
      containers:
        - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8

Specify by CPU and memory

If you don't need a specific instance type, define CPU and memory instead. This example uses a 1-core, 2 GiB instance:

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: hello-spec-2
spec:
  template:
    metadata:
      annotations:
        knative.aliyun.com/reserve-instance: enable
        knative.aliyun.com/reserve-instance-eci-use-specs: "1-2Gi"
    spec:
      containers:
        - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8

Configure ACS reserved instances

Alibaba Cloud Container Compute Service (ACS) reserved instances let you specify compute class and quality tiers. To use ACS, install ACK Virtual Node and add the knative.aliyun.com/reserve-instance-type: acs annotation.

Specify by compute class and quality

Use knative.aliyun.com/reserve-instance-acs-compute-class to set the compute class and knative.aliyun.com/reserve-instance-acs-compute-qos to set the compute quality. Both are optional.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
spec:
  template:
    metadata:
      annotations:
        knative.aliyun.com/reserve-instance: enable
        knative.aliyun.com/reserve-instance-type: acs
        # (Optional) Compute class for the ACS pod
        knative.aliyun.com/reserve-instance-acs-compute-class: "general-purpose"
        # (Optional) Compute quality for the ACS pod
        knative.aliyun.com/reserve-instance-acs-compute-qos: "default"
    spec:
      containers:
      - image: registry-vpc.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
        env:
        - name: TARGET
          value: "Knative"

Specify by CPU and memory

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go-resource
spec:
  template:
    metadata:
      annotations:
        knative.aliyun.com/reserve-instance: enable
        knative.aliyun.com/reserve-instance-type: acs
        knative.aliyun.com/reserve-instance-cpu-resource-request: "1"
        knative.aliyun.com/reserve-instance-memory-resource-request: "2Gi"
    spec:
      containers:
      - image: registry-vpc.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
        env:
        - name: TARGET
          value: "Knative"

Configure ECS reserved instances

Use a lower-cost ECS instance type to reduce idle costs. ECS reserved instances work well for GPU workloads.

GPU workloads

This example configures ecs.gn6i-c4g1.xlarge as a low-spec GPU reserved instance for a Qwen inference service. The standard instance uses a full GPU; the reserved instance uses a smaller spec to handle the first request at lower cost.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  labels:
    release: qwen
  name: qwen
  namespace: default
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/metric: "concurrency"
        # Enable and configure an ECS reserved instance. You can configure one or more instance types.
        knative.aliyun.com/reserve-instance: enable
        knative.aliyun.com/reserve-instance-type: ecs
        knative.aliyun.com/reserve-instance-ecs-use-specs: ecs.gn6i-c4g1.xlarge
      labels:
        release: qwen
    spec:
      containers:
      - command:
        - sh
        - -c
        - python3 -m vllm.entrypoints.openai.api_server --port 8080 --trust-remote-code
          --served-model-name qwen --model /mnt/models/Qwen-7B-Chat-Int8 --gpu-memory-utilization
          0.95 --quantization gptq --max-model-len=6144
        image: kube-ai-registry.cn-shanghai.cr.aliyuncs.com/kube-ai/vllm:0.4.1
        imagePullPolicy: IfNotPresent
        name: vllm-container
        resources:
          # Resource configuration for the standard instance
          limits:
            cpu: "16"
            memory: 60Gi
            nvidia.com/gpu: "1"
          requests:
            cpu: "8"
            memory: 36Gi
            nvidia.com/gpu: "1"
        volumeMounts:
        - mountPath: /mnt/models/Qwen-7B-Chat-Int8
          name: qwen-7b-chat-int8
      volumes:
      - name: qwen-7b-chat-int8
        persistentVolumeClaim:
          claimName: qwen-7b-chat-int8-dataset

Specify by CPU and memory

This example specifies a 1-core, 2 GiB ECS reserved instance:

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-resource
spec:
  template:
    metadata:
      annotations:
        knative.aliyun.com/reserve-instance: enable
        knative.aliyun.com/reserve-instance-type: ecs
        knative.aliyun.com/reserve-instance-cpu-resource-request: "1"
        knative.aliyun.com/reserve-instance-cpu-resource-limit: "1"
        knative.aliyun.com/reserve-instance-memory-resource-request: "2Gi"
        knative.aliyun.com/reserve-instance-memory-resource-limit: "2Gi"
    spec:
      containers:
      - image: registry-vpc.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
        env:
        - name: TARGET
          value: "Knative"

Configure a reserved instance pool

A single reserved instance handles the first request after idle. For services with frequent traffic spikes, expand to a pool with knative.aliyun.com/reserve-instance-replicas. When traffic arrives, warmed reserved instances respond immediately while standard instances scale out; once standard instances can carry the load, traffic is routed to them and the reserved pool scales back to zero.

This example creates a pool of 3 low-spec instances:

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: hello-reserve-pool
spec:
  template:
    metadata:
      annotations:
        knative.aliyun.com/reserve-instance: enable
        knative.aliyun.com/reserve-instance-replicas: "3"
        knative.aliyun.com/reserve-instance-eci-use-specs: "ecs.t6-c1m1.large,ecs.t5-lc1m2.small"
    spec:
      containers:
        - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:160e4dc8

Apply in production

Choose the lowest-cost instance type that reliably runs your application and serves at least one request. The reserved instance only needs to handle traffic until standard instances are ready — it doesn't need to match their specification.

Use a reserved pool for high-burst services. If your service receives sudden traffic spikes, configure multiple replicas with knative.aliyun.com/reserve-instance-replicas to absorb the initial load.

Account for continuous billing when sizing reserved instances. Reserved instances incur charges at all times, including during idle periods. Use the smallest instance type that can handle a single request to keep idle costs low.

Monitoring and alerting: Monitor Knative Service scaling to verify the handover from reserved to standard instances. Set response latency alerts for critical services.

Billing

Reserved instances incur charges continuously, even during idle periods. See billing details for each instance type:

Next steps