All Products
Search
Document Center

Elastic Container Instance:Configure an eci-profile to automatically use a DataCache

Last Updated:Apr 01, 2026

When you run many pods that depend on a DataCache, manually adding the DataCache annotation to each pod spec is error-prone and hard to maintain. The ECI Effect capability in eci-profiles lets you automatically inject the DataCache annotation into any pod that matches a label selector — no changes to individual pod specs required.

This topic explains how to configure an eci-profile selector to automatically add the k8s.aliyun.com/eci-data-cache-bucket annotation to pods that carry specific labels.

How it works

eci-profiles evaluate pod labels against all configured selectors. If a pod matches a selector's namespaceSelector or objectSelector criteria, eci-profile injects the annotations defined in the selector's effect field into the pod.

Prerequisites

Before you begin, ensure that you have:

  • kubectl access to the cluster with permission to edit ConfigMaps in the kube-system namespace

  • A bucket for storing DataCache data

Configure the eci-profile selector

Selector fields

Each entry in the selectors array must include a name field. The following fields are also available:

FieldRequiredDescription
nameYesA unique identifier for this selector
namespaceSelectorNoMatches pods based on the labels of their namespace. Use this to apply the annotation to all pods in namespaces that carry specific labels.
objectSelectorNoMatches pods based on the pod's own labels. Use this to target individual pods by their labels.
effectNoThe annotations and labels to inject into matching pods

Add a DataCache selector

  1. Edit the eci-profile ConfigMap.

    kubectl -n kube-system edit cm eci-profile
  2. Add a selector in the selectors section. The following example automatically injects the k8s.aliyun.com/eci-data-cache-bucket: "default" annotation into any pod labeled data-cache: "true".

    data:
      selectors: |
        [
          {
            "name": "datacache-selector",
            "objectSelector": {
              "matchLabels": {
                "data-cache": "true"
              }
            },
            "effect": {
              "annotations": {
                "k8s.aliyun.com/eci-data-cache-bucket": "default"
              }
            }
          }
        ]
  3. Create a DataCache. For more information, see Create a DataCache.

  4. Create a pod using the DataCache.

    kubectl create -f test-edc.yaml

    The following is a sample test-edc.yaml. The pod carries the data-cache: "true" label, which triggers eci-profile to inject the k8s.aliyun.com/eci-data-cache-bucket: "default" annotation automatically.

    Important

    When creating a pod with a DataCache, you must specify the bucket that stores the DataCache and the path in which the data is stored by using the HostPath parameter.

    apiVersion: v1
    kind: Pod
    metadata:
      name: test-edc
      labels:
        alibabacloud.com/eci: "true"
        data-cache: "true"   # Triggers eci-profile to inject the k8s.aliyun.com/eci-data-cache-bucket annotation
    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"   # Required: path where DataCache data is stored. Replace with the actual path.

What's next