文档

配置ECI Profile实现Pod编排

更新时间:

为了减少您对业务YAML的改动,ECI支持了ECI Profile功能。该功能可以提供集群维度的ECI资源视图,支持根据selector实现Pod编排。本文介绍如何配置ECI Profile。

ECI Profile介绍

ECI Profile功能包括以下能力:

  • ECI Scheduler

    在混合使用普通节点和虚拟节点(VNode)的场景下,一般可以通过配置Pod Label、配置Namespace Label,以及配置nodeSelector和tolerations的方式将Pod调度到VNode,以ECI来运行。但这些方式均需要对存量资源做一定修改,无法做到零侵入。

    针对上述情况,ECI Scheduler基于Mutating Webhook机制实现了一种新的调度机制,即在eci-profile中,您可以声明需要匹配的Namespace或者Pod的Label,对于Label能够匹配上的Pod,将被自动调度到VNode,以ECI来运行。

  • ECI Effect

    对于ECI的一些功能特性,例如指定ECS实例规格,启用镜像缓存等,需要在Pod中添加Annotation或者Label来实现。为了便于添加Annotation,ECI Effect实现了自动追加Annotation和Label的功能,即在eci-profile中,您可以声明需要匹配的Namespace或者Pod的Label,以及需要追加的Annotation和Label,对于Label能够匹配上的Pod,将自动追加配置的Annotation和Label。

    支持添加的Annotation,请参见ECI Pod Annotation

部署eci-profile组件

使用ECI Profile功能前,需要在集群中部署eci-profile组件。

  1. 将以下内容保存为eci-profile.yaml。

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: eci-profile
      namespace: kube-system
    data:
      selectors: |
        [
            {
                "name":"default-pod-selector",
                "objectSelector":{
                    "matchLabels":{
                        "alibabacloud.com/eci": "true"
                    }
                }
            },
            {
                "name":"default-namespace-selector",
                "namespaceSelector":{
                    "matchLabels":{
                        "alibabacloud.com/eci": "true"
                    }
                }
            }
        ]
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: alicloud-eci-profile
    rules:
      - apiGroups:
          - ""
        resources:
          - namespaces
        verbs:
          - get
          - list
          - watch
      - apiGroups:
          - ""
        resources:
          - events
        verbs:
          - create
          - patch
          - update
      - apiGroups:
          - ""
        resources:
          - configmaps
        verbs:
          - get
          - list
          - watch
          - create
          - patch
      - apiGroups:
          - ""
        resources:
          - nodes
        verbs:
          - get
      - apiGroups:
          - "admissionregistration.k8s.io"
        resources:
          - mutatingwebhookconfigurations
        verbs:
          - get
          - patch
          - create
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: alicloud-eci-profile
      namespace: kube-system
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: alicloud-eci-profile
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: alicloud-eci-profile
    subjects:
      - kind: ServiceAccount
        name: alicloud-eci-profile
        namespace: kube-system
    ---
    apiVersion: v1
    kind: Service
    metadata:
      labels:
        role: eci-profile
      name: eci-profile
      namespace: kube-system
    spec:
      ports:
        - port: 443
          targetPort: 443
      selector:
        app: eci-profile
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: alicloud-eci-profile
      namespace: kube-system
      labels:
        app: eci-profile
        webhook: eci-profile
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: eci-profile
      template:
        metadata:
          labels:
            app: eci-profile
        spec:
          serviceAccount: alicloud-eci-profile
          terminationGracePeriodSeconds: 60
          containers:
            - name: eci-profile
              image: registry.cn-hangzhou.aliyuncs.com/eci/eci-profile:v1.0.0
              imagePullPolicy: Always
              command:
                - /eci-profile
              args:
                - --profileProvider
                - cm
              resources:
                requests:
                  memory: 30M
                  cpu: 100m

    上述模板中,默认已添加2个selector:

    • default-pod-selector:可以将带有alibabacloud.com/eci: true标签的Pod自动调度到VNode。

    • default-namespace-selector:可以将带有alibabacloud.com/eci: true标签的Namespace下的Pod自动调度到VNode。

    另外,如果您想要将eci-profile组件调度到VNode,需要为其添加nodeSelector和tolerations:

    nodeSelector:
     k8s.aliyun.com/vnode: "true"
    tolerations:
    - key: k8s.aliyun.com/vnode
     operator: "Equal"
     value: "true"
     effect: "NoSchedule"
  2. 部署eci-profile组件。

    kubectl create -f eci-profile.yaml
  3. 查看部署结果。

    kubectl -n kube-system get pods

    预期返回:

    NAME                                                     READY   STATUS    RESTARTS   AGE
    alicloud-eci-profile-568d64cf84-f7sz8                    1/1     Running   0          26h

配置说明及示例

ECI Profile会读取eci-profile中的selectors去匹配Pod,对于Label能够匹配上的Pod,将自动调度到VNode,或者追加Annotation和Label,以便生效ECI的功能特性。

部署eci-profile后,您可以通过以下命令修改配置:

kubectl edit configmap eci-profile -n kube-system

单个selector的配置模板如下:

selectors: |
   [
    {
        "name":"demo",  
        "namespaceSelector":{  
            "matchLabels":{  
                "eci":"true"
            }
        },
        "objectSelector":{  
            "matchLabels":{  
                "eci":"true"
            }
        },
        "effect":{  
            "annotations":{
                "k8s.aliyun.com/eci-image-cache": "true"
            },
            "labels":{
                "created-by-eci":"true"
            }
        }
    }
   ]

上述模板中声明了一个名为demo的selector,可以实现以下功能:

如果Pod所属命名空间含有eci: true标签,并且Pod本身含有eci: true标签,则该Pod将自动被调度到VNode,并且增加"k8s.aliyun.com/eci-image-cache": "true"的Annotation,以及created-by-eci: true标签。

在每个selector中,您必须声明selector的name,可以根据需要声明以下信息:

  • namespaceSelector:要匹配的Namespace Label。

  • objectSelector:要匹配的Pod Label。

  • effect:需要动态追加的Annotation和Label。

注意

  • 在一个selector中,您至少要配置namespaceSelector和objectSelector中的一个,如果两者同时配置了,则Pod需要同时匹配两者。

  • 集群版本在1.16及以上时,默认支持objectSelector功能。如果版本低于1.16,请尝试通过feature-gate打开该功能。

配置示例一:将特定Pod调度到ECI实例

将含有created-by-eci: true标签,并且所属Namespace含有type: eci标签的Pod调度到VNode。YAML示例如下:

apiVersion: v1
kind: ConfigMap
metadata:
  name: eci-profile
  namespace: kube-system
data:
  selectors: |
    [
      {
        "name":"eci-selector-1",
        "namespaceSelector":{
          "matchLabels":{
            "type":"eci"
          }
        },
        "objectSelector":{
          "matchLabels":{
            "created-by-eci":"true"
          }
        }
      }
    ]

配置示例二:将特定Namespace下的所有Pod调度到ECI GPU实例

将含有gpu: true标签的Namespace下的所有Pod调度到VNode,并使用指定的GPU实例规格:ecs.gn6v-c8g1.2xlarge。YAML示例如下:

apiVersion: v1
kind: ConfigMap
metadata:
  name: eci-profile
  namespace: kube-system
data:
  selectors: |
    [
      {
        "name":"gpu-namespace-selector-1",
        "namespaceSelector":{
          "matchLabels":{
            "gpu":"true"
          }
        },
        "effect": {
          "annotations": {
            "k8s.aliyun.com/eci-use-specs":"ecs.gn6v-c8g1.2xlarge"
          }
        }
      }
    ]

配置示例三:将特定Pod调度到ECI AMD实例

将含有amd: true标签的Pod调度到VNode,并使用指定的AMD实例规格:ecs.c6a.xlarge。YAML示例如下:

apiVersion: v1
kind: ConfigMap
metadata:
  name: eci-profile
  namespace: kube-system
data:
  selectors: |
    [
      {
        "name":"amd-object-selector-1",
        "objectSelector":{
          "matchLabels":{
            "amd":"true"
          }
        },
        "effect": {
          "annotations": {
            "k8s.aliyun.com/eci-use-specs": "ecs.c6a.xlarge"
          }
        }
      }
    ]
  • 本页导读 (1)
文档反馈