全部產品
Search
文件中心

Elastic Container Instance:配置eci-profile實現自動使用DataCache

更新時間:Jul 06, 2024

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"   #掛載資料存放區路徑,請根據實際替換