All Products
Search
Document Center

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

Last Updated:Dec 29, 2023

eci-profiles provide the ECI Effect capability that can add annotations to existing pods that meet conditions to use features of Elastic Container Instances. This topic describes how to configure an eci-profile to automatically add an annotation to specific existing pods to use a DataCache.

Configuration description

eci-profiles provide the ECI Effect capability. In the selectors section in eci-profiles, you can specify the namespace labels or pod labels that need to be matched in the form of arrays, and specify the DataCache-related annotation that needs to be dynamically added. Then, the specified annotation is automatically added to the pods that have the specified labels. For more information, see Configure an eci-profile.

You can configure multiple selectors for the selectors parameter. You must specify the name of each selector. You can also specify the following information of each selector based on your requirements:

  • namespaceSelector: the namespace labels to match.

  • objectSelector: the pod labels to match.

  • effect: the annotations and labels to dynamically add to the pods.

You can add the k8s.aliyun.com/eci-data-cache-bucket annotation to specify the bucket that is used to store the DataCache.

Configuration example

  1. Edit the eci-profile configuration file.

    kubectl -n kube-system edit cm eci-profile
  2. Add selectors in the selectors section.

    The following code provides an example on how to automatically add the k8s.aliyun.com/eci-data-cache-bucket: "default" annotation to pods that have the data-cache: true label to specify the bucket that is used to store the DataCache.

    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. Use the DataCache that you created to create a pod.

    kubectl create -f test-edc.yaml

    Sample content of test-edc.yaml:

    Important

    When you use a DataCache to create a pod, you must specify the bucket that is used to store the DataCache. You also must specify 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"   # After the label is added to a pod, the eci-profile automatically adds the k8s.aliyun.com/eci-data-cache-bucket: "default" annotation to the pod to specify the bucket that is used to store the DataCache.
    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"   # Specify the path in which the data is stored. Replace the value with the actual value.