All Products
Search
Document Center

Container Service for Kubernetes:Use image caches to accelerate pod creation for Knative Services

Last Updated:Feb 27, 2026

When a Knative Service scales up or deploys a new revision, Container Service for Kubernetes (ACK) pulls container images from remote registries. For large images, this pull step dominates cold-start latency. Image caching eliminates most of that delay by pre-loading images into Elastic Container Instance (ECI) disk snapshots. Pods created from these snapshots skip the bulk of the image download.

How it works

ECI provides a Custom Resource Definition (CRD) called ImageCache. When you create an ImageCache resource, ECI pulls the specified images and writes them to a cloud disk snapshot. When a pod is scheduled on an elastic container instance, ECI creates a disk from the cached snapshot and attaches it to the instance, eliminating the need to pull every image layer from the registry. Only layers not present in the snapshot are downloaded.

ImageCache is a cluster-level resource shared across all namespaces in the cluster. Any Knative Service in any namespace can use it.

Performance example: A Docker image for Apache Flink of approximately 386.26 MB takes about 50 seconds to pull from Docker Hub. With an image cache, the same pod starts in about 5 seconds.

Important

These numbers are theoretical. Actual improvement depends on the number and size of images and the network connection quality to the image registry.

For details on image cache creation, lifecycle, and billing, see Overview of image caches.

Prerequisites

Before you begin, make sure that you have:

  • An ACK managed or dedicated cluster with Knative enabled

  • ECI (virtual node) configured in the cluster so that pods can be scheduled on elastic container instances

  • kubectl configured to connect to the cluster

  • Images pushed to an accessible container registry (such as Alibaba Cloud Container Registry)

Step 1: Create an ImageCache

  1. Save the following manifest as imagecache-secrets-test.yaml. Adjust the images, imageCacheSize, and retentionDays fields to match your workload. For the complete parameter reference, see Manage ImageCaches.

    ParameterDescription
    imagesList of container images to cache. Specify the full registry path and tag.
    imageCacheSizeSize of the cache disk in GiB. Set this large enough to hold all image layers.
    retentionDaysNumber of days to retain the cache snapshot before automatic deletion.
    k8s.aliyun.com/eci-image-cache: "true"Annotation that enables ImageCache reuse. If the cached image contains layers found in existing ImageCaches, ECI reuses those layers to accelerate cache creation.
       apiVersion: eci.alibabacloud.com/v1
       kind: ImageCache
       metadata:
         name: imagecache-sample-test
         annotations:
           k8s.aliyun.com/eci-image-cache: "true" # Enable reuse of existing ImageCaches.
       spec:
         images:
         - registry.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2
         - registry.cn-shanghai.aliyuncs.com/eci_open/busybox:1.30
         imageCacheSize:
          25
         retentionDays:
          7
  2. Create the ImageCache.

       kubectl create -f imagecache-secrets-test.yaml
  3. Verify that the ImageCache reaches the Ready state. Expected output: Wait until PHASE shows Ready and PROGRESS shows 100% before you proceed.

       kubectl get imagecache imagecache-sample-test
       NAME                              AGE   CACHEID                               PHASE   PROGRESS
       imagecache-sample-test            20h   imc-2zeditzeoemfhqor****              Ready    100%

Step 2: Use the ImageCache with a Knative Service

Two annotations control how a pod selects an ImageCache:

AnnotationBehavior
k8s.aliyun.com/eci-image-snapshot-idUse a specific ImageCache by its cache ID.
k8s.aliyun.com/eci-image-cacheAutomatically select the best-matching ImageCache.
If both annotations are set on the same pod, only k8s.aliyun.com/eci-image-snapshot-id takes effect.

Option A: Specify an ImageCache (recommended for production)

Set the k8s.aliyun.com/eci-image-snapshot-id annotation to the cache ID (the CACHEID value from Step 1).

Important

The specified ImageCache must be in the Ready state. If it is not, pod creation fails.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
spec:
  template:
    metadata:
      labels:
        app: helloworld-go
      annotations:
        k8s.aliyun.com/eci-image-snapshot-id: imc-2ze5tm5gehgtiiga****  # Replace with your cache ID.
    spec:
      containers:
        - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56

Option B: Automatically select an ImageCache

Set k8s.aliyun.com/eci-image-cache to "true". ECI filters all ImageCaches in the same region whose size does not exceed the temporary storage space of the elastic container instance, then selects the optimal one based on the following priority:

PriorityCriterionRule
1Match degreeCompares each ImageCache against the image registry and version specified in the pod. The highest overlap wins.
2Cache sizeAmong ImageCaches with equal match degree, the one whose size is closest to the total size of the required images wins.
3Creation timeAmong ImageCaches that tie on both match degree and cache size, the most recently created one wins.
If no ImageCache matches, ECI pulls the image from the registry and automatically creates a cache for future use. Set the image pull policy to IfNotPresent to prevent redundant downloads and improve caching efficiency.
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: helloworld-go
spec:
  template:
    metadata:
      labels:
        app: helloworld-go
      annotations:
        k8s.aliyun.com/eci-image-cache: "true"    # Automatically select the best ImageCache.
    spec:
      containers:
        - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56

Verify the deployment

After you deploy the Knative Service, confirm that the pod started and used the image cache:

  1. Check the Knative Service status. Verify that the READY column shows True.

       kubectl get ksvc helloworld-go
  2. Inspect pod events to confirm image cache usage. When an ImageCache is in effect, the pod skips the standard image pull step. Pull-related events are either absent or show significantly shorter durations.

       kubectl describe pod -l app=helloworld-go

Complementary cold-start strategies

Image caching reduces per-pod startup time by eliminating the image pull phase. Combine it with Knative-native strategies based on your latency requirements:

StrategyAnnotationEffect
Minimum replicasautoscaling.knative.dev/min-scale: "1"Keep at least one pod running to avoid scale-to-zero.
Scale-down delayautoscaling.knative.dev/scale-down-delay: "30s"Delay pod termination after traffic stops to absorb short traffic gaps.
Initial scaleautoscaling.knative.dev/initial-scale: "3"Control the number of replicas created when a new revision deploys.
These Knative annotations are upstream features and may require specific Knative versions. The values above are examples. Adjust them based on your traffic patterns and cost constraints. These strategies are independent of the ECI ImageCache feature.

References