All Products
Search
Document Center

Elastic Container Instance:Configure eci-profile to automatically use the ImageCache feature

最終更新日:Dec 12, 2023

To allow some Elastic Container Instance features to take effect, you must add annotations to pods. The eci-profile configuration file of elastic container instances provides the ECI Effect capability to automatically add annotations to pods. This topic describes how to configure eci-profile to automatically add annotations to pods if you want to use the ImageCache feature to accelerate the creation of the pods.

Description

When you use the ECI Effect capability of eci-profile, in selectors of the eci-profile configuration file, you must declare the namespace labels or pod labels to be matched in an array form, and declare ImageCache-related annotations that need to be dynamically added to pods. If a pod has the declared labels, the specified annotations are automatically added to the pod.

Note

For more information, see Configure an eci-profile.

The following table describes the ImageCache-related annotations that you can add to pods:

Usage method of ImageCache

Annotation

Example value

Description

Enable automatic match of image caches

k8s.aliyun.com/eci-auto-imc

"true"

Specifies whether to automatically match image caches. The default value is true, which indicates that the system automatically matches the most suitable image cache to create the pod based on the matching policy. The system selects the image cache based on the following order: the matching degree of the image, the size of the image, and the point in time when the image is created.

If no image cache is exactly matched, the system automatically creates a corresponding image cache when the system creates the pod.

k8s.aliyun.com/imc-perfect-match

"true"

Specifies whether all container images in the pod must match the image cache. Default value: false.

k8s.aliyun.com/imc-match-count-request

"2"

Specifies the number of container images in the pod that you want to exactly match the image cache.

Specify an image cache that you want to use

k8s.aliyun.com/eci-imc-id

imc-2zebxkiifuyzzlhl****

Specifies an image cache to create the pod.

The following code describes selectors.

  selectors: |
   [
    {
        "name":"demo",  # Required. The name of the selector.
        "namespaceSelector":{  # Optional. Namespace labels are matched.
            "matchLabels":{  # The labels to be matched. If you specify multiple labels, the relationship between the labels is AND.
                "app":"nginx"
            }
        },
        "objectSelector":{  # Optional. Pod labels are matched.
            "matchLabels":{  # The labels to be matched. If you specify multiple labels, the relationship between the labels is AND.
                "type":"test"
            }
        },
        "effect":{  # The annotations to be dynamically added.
            "annotations":{
                "k8s.aliyun.com/eci-auto-imc": "true"
            }
        }
    }
   ]

After you configure selectors, you can run the following command to check whether the selectors take effect. If the returned YAML file contains the configured selectors, the selectors take effect. If the returned YAML file does not contain the configured selectors, check whether the selectors are formatted correctly.

kubectl get mutatingwebhookconfigurations -o yaml vk-webhook

Example

Edit the eci-profile configuration file.

kubectl -n kube-system edit cm eci-profile

Add the following sample content to the selectors:

[
  ...
	{
    "name":"image-cache-selector-1",
    "objectSelector":{
      "matchLabels":{
        "image-cache":"true"
      }
    },
    "effect": {
      "annotations": {
        "k8s.aliyun.com/eci-imc-id": "imc-uf6ic***************"
      }
    }
  },
  {
    "name":"image-cache-selector-2",
      "namespaceSelector":{
      "matchLabels":{
        "image-cache":"true"
      }
    },
    "effect": {
      "annotations": {
        "k8s.aliyun.com/eci-auto-imc": "true"
      }
    }
  }
]

The preceding configuration contains two selectors:

  • image-cache-selector-1: If a pod contains the image-cache: true label, the "k8s.aliyun.com/eci-imc-id": "imc-uf6ic***************" annotation is automatically added to the pod and the specified image cache is used to accelerate the creation of the pod.

  • image-cache-selector-2: If a namespace contains the image-cache: true label, the "k8s.aliyun.com/eci-auto-imc": "true" annotation is automatically added to the pods in the namespace and image caches start to be automatically matched.