All Products
Search
Document Center

Configure Elastic Container Instance Profile

Last Updated: Jun 21, 2022

When you deploy an elastic container instance in Kubernetes based on Virtual Kubelet, pods may fail to be scheduled to or run on the elastic container instance. You can configure Elastic Container Instance Profile to resolve the issue. This topic describes Elastic Container Instance Profile and how to configure Elastic Container Instance Profile.

Introduction to Elastic Container Instance Profile

When you deploy an elastic container instance in Kubernetes based on Virtual Kubelet, pods may fail to be scheduled to the elastic container instance. After pods are scheduled to the elastic container instance, you must add pod annotations for specific Elastic Container Instance features such as image cache to take effect. In most cases, this type of issue is handled by cluster administrators. However, the current issue can be resolved only by requesting developers to modify the YAML file of the pod.

Elastic Container Instance Profile allows cluster administrators to schedule pods and modify pod configuration files. Elastic Container Instance Profile provides the following features:

  • ECI Scheduler

    When you use elastic container instances together with regular nodes, you can use one of the following methods to schedule pods to elastic container instances:

    These methods are not intrusion-free and require you to modify existing resources.

    Elastic Container Instance Scheduler implements a new scheduling mechanism based on mutating webhooks. You can declare the namespace or pod labels to be matched in Elastic Container Instance Profile. Pods that have the declared labels are automatically scheduled to elastic container instances.

  • ECI Effect

    You must add annotations or labels to pods for specific Elastic Container Instance features to take effect. Examples of these features include specifying Elastic Compute Service (ECS) instance types, enabling image caches, and configuring the Network Time Protocol (NTP) service. For more information, see Annotations supported by Elastic Container Instance.

    Elastic Container Instance Effect can automatically add annotations and labels. In Elastic Container Instance Profile, you can declare the namespace or pod labels to be matched and specify the annotations and labels to be added. If a pod has the declared labels, the specified annotations and labels are automatically added to the pod.

Configuration description

Elastic Container Instance Profile reads the eci-profile ConfigMap from the kube-system namespace and matches pods based on the selectors specified in the ConfigMap. If a pod has the labels contained in the selectors, the pod is automatically scheduled to the elastic container instance, or annotations and labels are automatically added to the pod for specific Elastic Container Instance features to take effect.

You can use one of the following methods to modify the eci-profile ConfigMap:

  • Run the kubectl edit command.

    kubectl edit configmap eci-profile -n kube-system
  • Use the Container Service for Kubernetes (ACK) console.

    1. Log on to the ACK console. On the Clusters page, find the cluster that you want to manage and click the cluster name.

    2. In the left-side navigation pane, choose Configurations > ConfigMaps.

    3. Select kube-system from the Namespace drop-down list.

    4. Find and modify the eci-profile ConfigMap.

The following file provides an example of an eci-profile ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: eci-profile
  namespace: kube-system
data:
  vpcId: "vpc-xxx"
  securityGroupId: "sg-xxx"
  vswitchIds: "vsw-111,vsw-222"
  enableClusterIp: "true"
  enableHybridMode: "false"
  enablePrivateZone: "false"
  selectors: |
    [
        {
            "name":"default-selector-1",
            "objectSelector":{
                "matchLabels":{
                    "alibabacloud.com/eci":"true"
                }
            }
        },
        {
            "name":"default-selector-2",
            "objectSelector":{
                "matchLabels":{
                    "eci":"true"
                }
            }
        },
        {
            "name":"default-selector-3",
            "namespaceSelector":{
                "matchLabels":{
                    "alibabacloud.com/eci":"true"
                }
            }
        },
        {
            "name":"default-selector-4",
            "namespaceSelector":{
                "matchLabels":{
                    "eci":"true"
                }
            }
        },
        {
            "name":"default-selector-5",
            "namespaceSelector":{  
                "matchLabels":{
                    "virtual-node-affinity-injection":"enabled"
                }
            },
            "effect":{  #The annotations and labels to be dynamically added.
            "annotations":{
                "k8s.aliyun.com/eci-image-cache": "true"
            },
            "labels":{
                "created-by-eci":"true"
            }
          }
        }
    ]

In the preceding example, the selectors section contains the configurations of Elastic Container Instance Scheduler and Elastic Container Instance Effect. You must specify a selector name for each selector. You can specify namespaceSelector, objectSelector, and effect based on your business requirements.

The following table describes some of the parameters of the ECI Effect configuration file.

Parameter

Description

vpcId

Specifies the ID of the virtual private cloud (VPC).

securityGroupId

Specifies the ID of the security group.

vswitchIds

Specifies the IDs of vSwitches. Separate multiple vSwitch IDs with commas (,).

enableClusterIp

Specifies whether to support cluster IP addresses.

enableHybridMode

Specifies whether to enable the hybrid cloud mode.

enablePrivateZone

Specifies whether to use Alibaba Cloud DNS PrivateZone to resolve domain names.

namespaceSelector

Specifies the namespace labels to match.

objectSelector

Specifies the pod labels to match.

effect

Specifies the annotations and labels to be dynamically added.

Note

You can configure Elastic Container Instance Scheduler and Elastic Container Instance Effect in the eci-profile ConfigMap. In addition, you can also configure to dynamically update other settings such as security groups, vSwitches, and resource groups without the need to restart Virtual Kubelet. This topic focuses on how to configure Elastic Container Instance Scheduler and Elastic Container Instance Effect by using selectors in the eci-profile ConfigMap.

Example on how to configure Elastic Container Instance Scheduler

In the selectors section of the eci-profile ConfigMap, you can declare the namespace or pod labels as arrays. The pods that have matching labels are automatically scheduled to elastic container instances.

Example:

  selectors: |
   [
      {
        "name":"demo",  #Required. The name of the selector.
        "namespaceSelector":{  #Optional. The namespace labels to be matched. You must specify namespaceSelector, objectSelector, or both.
            "matchLabels":{  #The labels to be matched. If you specify multiple labels, the relationship between the labels is AND.
                "department":"bigdata"
            }
        },
        "objectSelector":{  #Optional. The pod labels to be matched. You must specify namespaceSelector, objectSelector, or both.
            "matchLabels":{  #The labels to be matched. If you specify multiple labels, the relationship between the labels is AND.
                "type":"offline-task"
              }
          }
      }
   ]
Notice

In a selector, you must configure namespaceSelector, objectSelector, or both. If you configure both namespaceSelector and objectSelector, only pods that have all labels specified in both namespaceSelector and objectSelector can be automatically scheduled to the elastic container instance.

In the preceding example, a selector named demo is declared to implement the following feature:

If the namespace of a pod has the department=bigdata label and the pod has the type=offline-task label, the pod is automatically scheduled to the elastic container instance.

Example on how to configure Elastic Container Instance Effect

In the selectors section of the eci-profile ConfigMap, you can declare the namespace or pod labels as arrays and specify the annotations and labels to be dynamically added. If a pod has the declared labels, the specified annotations and labels are automatically added to the pod.

Example:

  selectors: |
   [
    {
        "name":"demo",  #Required. The name of the selector.
        "namespaceSelector":{  #Optional. The namespace labels to be matched.
            "matchLabels":{  #The labels to be matched. If you specify multiple labels, the relationship between the labels is AND.
                "department":"bigdata"
            }
        },
        "objectSelector":{  #Optional. The pod labels to be matched.
            "matchLabels":{  #The labels to be matched. If you specify multiple labels, the relationship between the labels is AND.
                "type":"offline-task"
            }
        },
        "effect":{  #The annotations and labels to be dynamically added.
            "annotations":{
                "k8s.aliyun.com/eci-image-cache": "true"
            },
            "labels":{
                "created-by-eci":"true"
            }
        }
    }
   ]
Notice

  • In a selector, you can configure namespaceSelector and objectSelector based on your business requirements. If neither namespaceSelector or objectSelector are configured, the effect settings take effect on all the pods that are scheduled to the elastic container instance.

  • If you configure multiple selectors, the selectors are matched in sequence. After pods are matched, the annotations and labels specified in the effect settings are automatically added to the pods. These annotations and labels do not overwrite existing annotations and labels of the pods. If duplicate annotations or labels exist, the annotations or labels that have higher priorities are used. The existing annotations and labels of the pods have a higher priority than the annotations and labels specified in the effect settings of matched selectors. The priorities of annotations or labels in the effect settings of the selectors descend in the order in which the selectors are matched.

In the preceding example, a selector named demo is declared to implement the following feature:

If the namespace of a pod has the department=bigdata label and the pod has the type=offline-task label, the pod is automatically scheduled to the elastic container instance. At the same time, the image cache feature is enabled, and the created-by-eci=true label is added to the pod.