文档

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

更新时间:

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

配置说明

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

selectors中可以包含多个selector,在每个selector中,您必须声明selector的name,可以根据需要声明以下信息:

  • namespaceSelector:要匹配的Namespace Label。

  • objectSelector:要匹配的Pod Label。

  • effect:要动态追加的Annotation和Label。

可以添加的DataCache相关Annotation为k8s.aliyun.com/eci-data-cache-bucket,用于指定DataCache Bucket。

配置示例

  1. 编辑eci-profile配置文件。

    kubectl -n kube-system edit cm eci-profile
  2. 在selectors中添加selector。

    内容示例如下,可以为带有data-cache: true的Label的Pod自动追加k8s.aliyun.com/eci-data-cache-bucket: "default"的Annotation,指定DataCache Bucket。

    data:
      selectors: |
        [
          {
            "name": "datacache-selector",
            "objectSelector": {
              "matchLabels": {
                "data-cache": "true"
              }
            },
            "effect": {
              "annotations": {
                "k8s.aliyun.com/eci-data-cache-bucket": "default"
              }
            }
          }
        ]
  3. 创建DataCache。具体操作,请参见创建DataCache

  4. 使用DataCache创建Pod。

    kubectl create -f test-edc.yaml

    test-edc.yaml的内容示例如下:

    重要

    使用DataCache创建Pod时,在指定DataCache Bucket的基础上,还需要通过挂载HostPath的方式挂载数据存储的路径。

    apiVersion: v1
    kind: Pod
    metadata:
      name: test-edc
      labels: 
        alibabacloud.com/eci: "true"
        data-cache: "true"   #添加Label后,eci-profile会自动追加Annotation来指定DataCache Bucket
    spec:
      containers:
        - name: model
          image: registry.cn-shanghai.aliyuncs.com/eci_open/nginx:1.14.2
          command: ["sleep", "999999"]
          volumeMounts:
            - name: "model"
              mountPath: "/model"
      volumes:        
        - name: "model"
          hostPath:
            path: "/model/test"   #挂载数据存储路径,请根据实际替换
  • 本页导读 (1)
文档反馈