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:
kubectlaccess to the cluster with permission to edit ConfigMaps in thekube-systemnamespaceA 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:
| Field | Required | Description |
|---|---|---|
name | Yes | A unique identifier for this selector |
namespaceSelector | No | Matches pods based on the labels of their namespace. Use this to apply the annotation to all pods in namespaces that carry specific labels. |
objectSelector | No | Matches pods based on the pod's own labels. Use this to target individual pods by their labels. |
effect | No | The annotations and labels to inject into matching pods |
Add a DataCache selector
Edit the eci-profile ConfigMap.
kubectl -n kube-system edit cm eci-profileAdd a selector in the
selectorssection. The following example automatically injects thek8s.aliyun.com/eci-data-cache-bucket: "default"annotation into any pod labeleddata-cache: "true".data: selectors: | [ { "name": "datacache-selector", "objectSelector": { "matchLabels": { "data-cache": "true" } }, "effect": { "annotations": { "k8s.aliyun.com/eci-data-cache-bucket": "default" } } } ]Create a DataCache. For more information, see Create a DataCache.
Create a pod using the DataCache.
kubectl create -f test-edc.yamlThe following is a sample
test-edc.yaml. The pod carries thedata-cache: "true"label, which triggers eci-profile to inject thek8s.aliyun.com/eci-data-cache-bucket: "default"annotation automatically.ImportantWhen 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
HostPathparameter.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
Configure an eci-profile — Learn about the full eci-profile structure and all available fields.
Create a DataCache — Create and manage DataCache resources.