文档

配置eci-profile实现自动使用ImageCache

更新时间:

eci-profile支持ECI Effect能力,可以为满足条件的Pod自动追加Annotation来使用ECI的功能特性。本文介绍如何配置eci-profile,为特定Pod自动追加Annotation来使用ImageCache功能。

配置说明

基于eci-profile的ECI Effect能力,在eci-profile配置文件的selectors中,支持以数组的形式声明需要匹配的Namespace或者Pod的Label,以及需要动态追加的ImageCache相关Annotation。对于Label能够匹配上的Pod,将自动追加配置的Annotation。

说明

更多关于eci-profile的信息,请参见配置eci-profile

支持为Pod添加的ImageCache相关Annotation如下:

使用方式

配置项

示例值

说明

自动匹配

k8s.aliyun.com/eci-auto-imc

"true"

是否自动匹配ImageCache,默认为true,表示系统会根据匹配策略自动匹配最优的ImageCache创建Pod。匹配策略的优先级从高到低依次为:镜像匹配度、匹配的镜像大小、创建时间。

如果没有完全匹配,系统会在创建Pod的同时自动创建对应的ImageCache。

k8s.aliyun.com/imc-perfect-match

"true"

Pod内所有容器镜像是否均要完全匹配ImageCache。默认为false。

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

"2"

Pod内要完全匹配ImageCache的容器镜像个数。

明确指定

k8s.aliyun.com/eci-imc-id

imc-2zebxkiifuyzzlhl****

明确指定使用某个ImageCache存创建Pod。

selectors说明如下:

  selectors: |
   [
    {
        "name":"demo",  #必填,不能为空
        "namespaceSelector":{  #选填,匹配Namespace Label
            "matchLabels":{  #需要匹配的Label,如果填写多个,为与关系
                "app":"nginx"
            }
        },
        "objectSelector":{  #选填,匹配Pod Label
            "matchLabels":{  #需要匹配的Label,如果填写多个,为与关系
                "type":"test"
            }
        },
        "effect":{  #需要动态追加的Annotation
            "annotations":{
                "k8s.aliyun.com/eci-auto-imc": "true"
            }
        }
    }
   ]

配置selectors后,您可以通过以下命令确认selectors是否生效。如果返回的YAML中已包含配置的selectors,则表示配置成功;如果未包含selectors,请检查selectors的格式是否有误。

kubectl get mutatingwebhookconfigurations -o yaml vk-webhook

配置示例

编辑eci-profile配置文件。

kubectl -n kube-system edit cm eci-profile

在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"
      }
    }
  }
]

上述配置包含了2个selector:

  • image-cache-selector-1:如果Pod带有image-cache: true的Label,将自动追加 "k8s.aliyun.com/eci-imc-id": "imc-uf6ic***************"的Annotation,使用指定的镜像缓存。

  • image-cache-selector-2:如果Pod所属Namespace带有image-cache: true的Label,将自动追加 "k8s.aliyun.com/eci-auto-imc": "true"的Annotation,开启自动匹配镜像缓存。

  • 本页导读 (1)
文档反馈