文档

指定ECS和ECI的资源分配

更新时间:

在ACK集群中部署服务时,您可以使用容忍度和节点亲和性来声明只使用ECS或ECI弹性资源,或者是在ECS资源不足时自动申请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到其他节点。

前提条件

操作步骤

下文将介绍如何通过污点、容忍度、节点亲和性完成以下调度策略:

  • 只使用ECI:只使用ECI弹性资源,不使用集群的ECS资源。

  • 优先使用ECS:当前集群ECS资源不足时,使用ECI弹性资源。

  • 只使用ECS:只使用集群现有的ECS资源。

只使用ECI

展开查看YAML文件

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

展开查看YAML文件

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

当您希望将负载优先部署在带有标签label_1=key_1的ECS节点池上,且该节点池资源不足时使用virtual-node进行弹性伸缩时,可以通过以下方式部署。

展开查看YAML文件

apiVersion: apps/v1
kind: Deployment
metadata:
  name: some-ecs-prefer
spec:
  replicas: 2
  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:
# 指定Pod必须调度到带有label_1:key_1或type:virtual-kubelet标签的节点上。
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: label_1
                operator: In
                values:
                - key_1
            - matchExpressions:
              - key: type
                operator: In
                values:
                - virtual-kubelet
# 指定Pod优先调度到带有label_1:key_1标签的节点上。
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            preference:
              matchExpressions:
              - key: label_1
                operator: In
                values:
                - key_1
          - weight: 1
            preference:
              matchExpressions:
              - key: type
                operator: In
                values:
                - virtual-kubelet
      containers:
      - name: my-container
        image: nginx
说明
  • 如果您在与nodeAffinity类型关联的nodeSelectorTerms中指定多个条件,只要其中一个nodeSelectorTerms满足(各个条件按逻辑或操作组合)时,Pod就可以被调度到节点上。

  • 如果您在与nodeSelectorTerms中的条件相关联的单个matchExpressions字段中指定多个表达式,则只有当所有表达式都满足(各表达式按逻辑与操作组合)时,Pod才能被调度到节点上。

  • 使用preferredDuringSchedulingIgnoredDuringExecution实现优先ECS调度时,不能保证仅在ECS资源不足时才调度到ECI上。也会存在ECS资源充足的情况下,Pod也会被调度到ECI上的场景。

只使用ECS

为了避免您使用价格较为昂贵的ECI实例,Virtual Node默认有污点(Taints)。

      virtual-kubelet.io/provider=alibabacloud:NoSchedule

因此,只要您未配置对于该污点的容忍度,Pod将只调度到ECS上。

展开查看YAML文件

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

  • 本页导读 (1)
文档反馈