在ACK集群中部署服务时,您可以使用容忍度和节点亲和性来申明只使用ECS或ECI弹性资源,或者是在ECS资源不足时自动申请ECI资源。通过配置ECI调度策略可以满足您在不同工作负载场景下对弹性资源的不同需求。本文介绍如何配置ECI调度策略。

索引

相关概念

  • 污点:ACK集群中的Virtual Node默认都会打上污点virtual-kubelet.io/provider=alibabacloud:NoSchedule,以避免您在不知情的情况下使用ECI弹性资源。
  • 容忍度:容忍度(Toleration)应用于Pod上。容忍度允许调度器将该Pod调度到带有对应污点的Node。在ACK集群中,需要配置以下Toleration来容忍污点virtual-kubelet.io/provider=alibabacloud:NoSchedule,才能让Pod使用ECI资源。
          tolerations:
          - key: virtual-kubelet.io/provider
            operator: Equal
            value: alibabacloud
            effect: NoSchedule
  • 节点亲和性:节点亲和性(nodeAffinity)规定了Pod调度时的软需求或者偏好,且在这种偏好不被满足时成功调度该Pod到其他节点。

前提条件

已在ACK集群中(包括ACK标准版、ACK Pro版以及ACK专有版)部署ack-virtual-node。具体操作,请参见ACK使用ECI

操作步骤

下文将介绍如何通过污点、容忍度、节点亲和性,完成以下调度策略:
  • 只使用ECI:只使用ECI弹性资源,不使用集群的ECS资源。
  • 优先使用ECS:当前集群ECS资源不足时,使用ECI弹性资源。
  • 只使用ECS:只使用集群现有的ECS资源。

只使用ECI

apiVersion: apps/v1
kind: Deployment
metadata:
  name: eci-only
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      tolerations:
      - key: virtual-kubelet.io/provider
        operator: Equal
        value: alibabacloud
        effect: NoSchedule
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: type
                operator: In
                values:
                - virtual-kubelet
      containers:
      - name: my-container
        image: nginx
            

优先使用ECS

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ecs-prefer
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      tolerations:
      - key: virtual-kubelet.io/provider
        operator: Equal
        value: alibabacloud
        effect: NoSchedule
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 1
            preference:
              matchExpressions:
              - key: type
                operator: NotIn
                values:
                - virtual-kubelet
      containers:
      - name: my-container
        image: nginx

只使用ECS

为了避免您使用价格较为昂贵的ECI实例,Virtual Node默认有污点(Taints)。
      virtual-kubelet.io/provider=alibabacloud:NoSchedule
因此,只要您未配置对于该污点的容忍度,Pod将只调度到ECS上。
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ecs-only
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-container
        image: nginx
重要 在ACK Pro版集群中,已有的通过Annotation alibabacloud.com/burst-resource: eci配置ECI调度策略的方式目前依然支持,但不推荐使用。