Kubernetes:从默认计划中排除节点

tba*_*ack 3 kubernetes google-kubernetes-engine

是否可以创建一个节点池,调度程序将默认忽略该节点池,但节点选择器可以将其作为目标?

Jan*_*art 6

如果您的节点池具有静态大小或至少它不是自动缩放,那么这很容易实现.

首先,污染该池中的节点:

kubectl taint node \
  `kubectl get node -l cloud.google.com/gke-nodepool=my-pool -o name` \
  dedicated=my-pool:NoSchedule
Run Code Online (Sandbox Code Playgroud)

Kubernetes版本> = 1.6

然后在您的Pod(模板)中添加需要能够在这些节点上运行的值affinitytolerationsspec::

spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: dedicated
            operator: In
            values: ["my-pool"]
  tolerations: 
  - key: "key"
    operator: "Equal"
    value: "value"
    effect: "NoSchedule"
Run Code Online (Sandbox Code Playgroud)

前1.6

然后将这些注释添加到需要能够在这些节点上运行的Pod(模板):

annotations:
  scheduler.alpha.kubernetes.io/tolerations: >
    [{"key":"dedicated", "value":"my-pool"}]
  scheduler.alpha.kubernetes.io/affinity: >
    {
      "nodeAffinity": {
        "requiredDuringSchedulingIgnoredDuringExecution": {
          "nodeSelectorTerms": [
            {
              "matchExpressions": [
                {
                  "key": "dedicated",
                  "operator": "In",
                  "values": ["my-pool"]
                }
              ]
            }
          ]
        }
      }
    }
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅设计文档.

自动缩放节点组

您需要将--register-with-taints参数添加到kubelet:

使用给定的taints列表注册节点(以逗号分隔<key>=<value>:<effect>).如果register-node为false,则为no-op.

在另一个答案中,我给出了一些如何坚持这种设置的例子.GKE现在还特别支持污染节点池