All Products
Search
Document Center

Container Service for Kubernetes:Best practices for configuring AI model inference services in Knative

Last Updated:Sep 24, 2026

Knative is well-suited for AI model inference: it handles traffic spikes through auto scaling, scales pods to zero when idle, and lets you allocate GPU resources flexibly across workloads. This guide covers configuration practices for each layer of a Knative-based inference service—model loading, concurrency, auto scaling, GPU sharing, probes, and deployment strategies.

Accelerated model deployment

AI model files are large. Packaging them inside container images creates two problems: images become too large to pull quickly, and model versions get locked to image versions. Instead, store model files in Object Storage Service (OSS) or File Storage NAS (NAS), then mount the storage into your Knative Service pods using a persistent volume claim (PVC).

To further accelerate model loading, use Fluid—a distributed dataset orchestration and acceleration engine that can load large language models within seconds by caching data on local SSD.

Prerequisites

Before you begin, make sure you have:

Step 1: Define a Dataset

Create a Dataset custom resource (CR) and a JindoRuntime CR to declare your model's location in OSS and configure SSD caching.

apiVersion: v1
kind: Secret
metadata:
  name: access-key
stringData:
  fs.oss.accessKeyId: your_ak_id          # Replace with your AccessKey ID.
  fs.oss.accessKeySecret: your_ak_skrt    # Replace with your AccessKey secret.
---
apiVersion: data.fluid.io/v1alpha1
kind: Dataset
metadata:
  name: oss-data
spec:
  mounts:
  - mountPoint: "oss://{Bucket}/{path-to-model}"  # Replace with your OSS bucket and model path.
    name: xxx
    path: "{path-to-model}"                        # Replace with the model path to load.
    options:
      fs.oss.endpoint: "oss-cn-beijing.aliyuncs.com"  # Replace with your OSS bucket endpoint.
    encryptOptions:
      - name: fs.oss.accessKeyId
        valueFrom:
          secretKeyRef:
            name: access-key
            key: fs.oss.accessKeyId
      - name: fs.oss.accessKeySecret
        valueFrom:
          secretKeyRef:
            name: access-key
            key: fs.oss.accessKeySecret
  accessModes:
    - ReadOnlyMany
---
apiVersion: data.fluid.io/v1alpha1
kind: JindoRuntime
metadata:
  name: oss-data
spec:
  replicas: 2
  tieredstore:
    levels:
      - mediumtype: SSD
        volumeType: emptyDir
        path: /mnt/ssd0/cache
        quota: 100Gi
        high: "0.95"
        low: "0.7"
  fuse:
    properties:
      fs.jindofsx.data.cache.enable: "true"
    args:
      - -okernel_cache
      - -oro
      - -oattr_timeout=7200
      - -oentry_timeout=7200
      - -ometrics_port=9089
    cleanPolicy: OnDemand

Step 2: Mount the PVC

After you apply the Dataset CR and JindoRuntime CR, the system automatically creates a PVC with the same name as the Dataset. Mount this PVC in your Knative Service to make the cached model available inside the container.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: sd-backend
spec:
  template:
    spec:
      containers:
        - image: <YOUR-IMAGE>    # Replace with your container image name.
          name: image-name
          ports:
            - containerPort: xxx
              protocol: TCP
          volumeMounts:
            - mountPath: /data/models  # The path where the model is loaded inside the container.
              name: data-volume
      volumes:
        - name: data-volume
          persistentVolumeClaim:
            claimName: oss-data    # Must match the Dataset name.

For more information, see Use JindoFS to accelerate access to OSS and Use EFC to accelerate access to NAS file systems.

Step 3: Speed up image pulls with image caches

Container images for AI inference are large—they bundle CUDA, PyTorch-GPU, and other dependencies. When Knative scales out pods on elastic container instances, slow image pulls delay startup. Use ImageCache to pre-build a cached snapshot of the image so pods can start within seconds.

apiVersion: eci.alibabacloud.com/v1
kind: ImageCache
metadata:
  name: imagecache-ai-model
  annotations:
    k8s.aliyun.com/eci-image-cache: "true"  # Enable cache reuse.
spec:
  images:
  - <YOUR-IMAGE>
  imageCacheSize:
    25    # Cache size in GiB.
  retentionDays:
    7     # Number of days to retain the cache.

For more information, see Use ImageCache to accelerate the creation of elastic container instances.

Graceful pod shutdown

If an application uses HTTP probing, after the application pods receive the SIGTERM signal, the pods enter the Not Ready state so no new requests are routed to them. However, Knative's queue-proxy may still forward in-flight requests for a short period after SIGTERM. Set timeoutSeconds to 1.2× your maximum request timeout to give those requests time to complete.

For example, if your longest request takes 10 seconds, set timeoutSeconds to 12:

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
  namespace: default
spec:
  template:
    spec:
      timeoutSeconds: 12

Configure concurrency

Concurrency settings determine how many requests a single pod handles at a time. Tuning them correctly improves throughput and prevents overload.

Hard concurrency limit (containerConcurrency): An enforced cap. Requests above the limit queue and wait for capacity.

Warning

Use a hard limit only when your application has a strict ceiling on safe concurrency. A low hard limit reduces throughput, increases latency, and can cause additional cold starts.

Soft concurrency limit (autoscaling.knative.dev/target): A non-strict target. Traffic spikes may temporarily exceed it. This is the safer default for most inference workloads.

Target utilization (autoscaling.knative.dev/target-utilization-percentage): Controls how close to the limit Knative tries to stay. Set it close to 100% to maximize pod utilization before triggering scale-up.

For more information, see Configure the soft concurrency limit.

Auto scaling

Before tuning auto scaling, measure your pod startup time—it determines which parameters matter most.

For full parameter reference, see Enable auto scaling to withstand traffic fluctuations.

Scaling modes

Knative's autoscaler runs in two modes:

  • Stable mode: makes scaling decisions based on traffic averaged over the stable window. Suitable for normal, predictable traffic.

  • Panic mode: reacts faster using a shorter window to handle sudden traffic spikes. The panic window is a percentage of the stable window.

Stable window

Set the stable window to at least 2× your average pod startup time. A window shorter than pod startup time causes the autoscaler to undershoot because newly launched pods aren't counted yet.

Parameter Global key Per-revision annotation Default
Stable window stable-window autoscaling.knative.dev/window 60s
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/window: "40s"

Panic window

The panic window is a percentage of the stable window.

Parameter Global key Per-revision annotation Valid range Default
Panic window percentage panic-window-percentage autoscaling.knative.dev/panic-window-percentage 1.0–100.0 10.0
Warning

A short panic window can cause excessive pod creation when startup times are long. If the stable window is 30 seconds and the panic window is 10%, the autoscaler makes decisions based on 3 seconds of data. If pods take 30 seconds to start, the autoscaler keeps creating pods during the entire startup period, resulting in a large overshoot. Do not reduce the panic window until other parameters are confirmed to work correctly. If your stable window is 2× the average pod startup time, set the panic window to 50% as a safe starting point.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld
  namespace: default
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/panic-window-percentage: "20.0"

Panic mode threshold

The panic threshold is the ratio of incoming traffic to current service capacity at which panic mode activates.

Parameter Global key Per-revision annotation Valid range Default
Panic threshold percentage panic-threshold-percentage autoscaling.knative.dev/panic-threshold-percentage ≥110.0 200.0

Start with the default (200%) and adjust after observing your traffic patterns and latency tolerance.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld
  namespace: default
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/panic-threshold-percentage: "150.0"

Scale-up rate and scale-down rate

The default rates work for most scenarios. Test any changes in a staging environment before applying them to production.

Scale-up rate: Controls how quickly pods can be added. Increase this if pod startup is slow because new pods wait for resources to be allocated.

apiVersion: v1
kind: ConfigMap
metadata:
  name: config-autoscaler
  namespace: knative-serving
data:
  max-scale-up-rate: "500.0"

Scale-down rate: Set to at least the average pod startup time to avoid aggressive scale-down that immediately triggers a new scale-up. The value is a ratio: 4.0 means the pod count can drop to at most 1/4 of the current count per scaling cycle.

To reduce costs, increase the scale-down rate so pods are removed quickly when traffic drops. For services with a small number of pods, reduce the scale-down rate to maintain stability and avoid repeated scaling.

apiVersion: v1
kind: ConfigMap
metadata:
  name: config-autoscaler
  namespace: knative-serving
data:
  max-scale-down-rate: "4.0"

Scale-down delay

A scale-down delay holds pods for a fixed period before removing them. This prevents the autoscaler from aggressively removing pods and then immediately recreating them when a new request arrives.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
  namespace: default
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/scale-down-delay: "2m"  # Keep pods for 2 minutes after scale-down decision.

Scale bounds

Minimum replicas

autoscaling.knative.dev/min-scale sets the floor on the number of running pods.

Use case Recommended value
Always-available service with low traffic 1
Service that may receive traffic spikes >1
Allow scale to zero when idle 0
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld
  namespace: default
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/min-scale: "0"

Maximum replicas

autoscaling.knative.dev/max-scale caps the number of pods. Set this to stay within your resource quota.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld
  namespace: default
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/max-scale: "3"

Initial scale

autoscaling.knative.dev/initial-scale sets the target replica count for a revision on first deployment. Once the revision reaches this count and is marked Ready, this value no longer applies—the autoscaler takes over based on actual traffic and the replica count may drop if traffic is low. Set it to about 1.2× your current pod count when doing traffic-shifting rollouts so the new revision has capacity before traffic arrives.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
  namespace: default
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/initial-scale: "3"

GPU sharing

Container Service for Kubernetes (ACK) supports GPU sharing through cGPU, which provides GPU memory isolation between containers. To enable GPU sharing in a Knative Service, set aliyun.com/gpu-mem under resources.limits.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
  namespace: default
spec:
  template:
    spec:
      containerConcurrency: 1
      containers:
      - image: registry-vpc.cn-hangzhou.aliyuncs.com/demo-test/test:helloworld-go
        name: user-container
        ports:
        - containerPort: 6666
          name: http1
          protocol: TCP
        resources:
          limits:
            aliyun.com/gpu-mem: "3"  # GPU memory in GiB allocated to this container.

Probes

Knative probes services more frequently than standard Kubernetes to minimize cold start latency. Configure both liveness and readiness probes for your inference containers.

  • Liveness probe: Monitors container health. If the probe fails, Kubernetes restarts the container.

  • Readiness probe: Controls traffic routing. Only pods that pass the readiness probe receive requests.

TCP vs HTTP:

  • TCP probe: does not open the listening port until all components are loaded and the containers are ready.

  • HTTP probe: passes only when the endpoint returns a successful response. This is more accurate for inference services that have a warm-up phase.

Set periodSeconds to a value shorter than the default 10 seconds to reduce the delay between a pod becoming ready and traffic being routed to it.

For more information, see Configure port probing in Knative.

Scale to zero

When a Knative Service receives no traffic, Knative can scale its pods to zero, eliminating resource costs for idle models.

For workloads with many models, create a separate Knative Service for each model. This keeps the business logic in each Service simple and allows each model to scale independently.

When a client first accesses an idle model, Knative scales up from zero. To reduce the cold start impact, configure a reserved instance so at least one warm pod is always available.

For more information, see Configure a reserved instance.

Canary releases

Knative keeps the old revision running until the new one is ready, ensuring continuity during deployments.

Control the traffic split using the percent field. The valid range is 10%–100%. Set it to 100% to fully cut over to the new revision and retire the old one immediately.

When resources are constrained—for example, 500 pods running with only 300 more available—use a low traffic percentage to limit how fast the old revision scales down. Setting too high a percentage in this situation can cause the old revision to scale down faster than the new one scales up, leaving insufficient capacity.

For more information, see Perform a canary release based on traffic splitting for a Knative Service.

Colocate ECS instances and elastic container instances

Configure ResourcePolicies to mix Elastic Compute Service (ECS) instances with elastic container instances. ECS instances run during normal traffic; elastic container instances absorb traffic spikes.

  • Scale up: Knative schedules pods to ECS instances first. When pods exceed the predefined limit or ECS capacity is exhausted, new pods go to elastic container instances.

  • Scale down: Pods on elastic container instances are removed first.

image

For more information, see Colocate ECS instances and elastic container instances in Knative.