首页 > 解决方案 > NodeSelector 不适用于多个节点池?

问题描述

TL;DR:NodeSelector 忽略来自另一个 NodePool 的节点。如何使用标签 nodeSelector 或其他技术在更多 NodePools 中分发 pod?

我有两个这样的节点池:

...
# Spot node pool
resource "azurerm_kubernetes_cluster_node_pool" "aks_staging_np_compute_spot" {
  name                  = "computespot"
  (...)
  vm_size               = "Standard_F8s_v2"
  max_count             = 2
  min_count             = 2
  (...)
  priority = "Spot"
  eviction_policy = "Delete"
  (...)
  node_labels = {
    "pool_type" = "compute"
  }

# Regular node pool
resource "azurerm_kubernetes_cluster_node_pool" "aks_staging_np_compute_base" {
  name                  = "computebase"
  (...)
  vm_size               = "Standard_F8s_v2"
  max_count             = 2
  min_count             = 2
  node_labels = {
    "pool_type" = "compute"
  }

两个池都部署在 AKS 中,并且所有节点都处于正常状态。请注意两点:

(我的集群中还有 20 个不同标签的其他节点并不重要。)

然后我有一个这样的部署(为了简洁省略了不相关的行):

apiVersion: apps/v1
kind: Deployment
metadata:
  (...)
spec:
  replicas: 4
  selector:
    matchLabels:
      app: myapp
  template:
    (...)
    spec:
      nodeSelector:
        pool_type: compute
      (...)
      containers:
        (...)

还有一个tolerations用于接受 Azure 现场实例的条目。它显然有效。

tolerations:
        - key: "kubernetes.azure.com/scalesetpriority"
          operator: "Equal"
          value: "spot"
          effect: "NoSchedule"

问题是应用程序仅部署在一个节点池上("computespot"在这种情况下),并且从不接触另一个节点池( computebase)。即使标签和单个节点的大小相同。

如何解决?

标签: kubernetesazure-akskubernetes-podspot-instances

解决方案


找到了使用 pod 亲和性的解决方案。

spec:
      # This didn't work:
      #
      # nodeSelector:
      #   pool_type: compute 
      # 
      # But this does:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                - key: pool_type
                  operator: In
                  values:
                  - compute 

我不知道原因,因为我们仍在处理一个标签。如果有人知道,请分享。


推荐阅读