NodeAffinity 不适用于 Kubernetes 1.23+,PG Pod 部署在*未标记的* Kubernetes 节点上

问题描述 投票:0回答:1

我们有一个由

4
节点组成的集群,我们称它们为
node1 ,node2 ,node3 ,node4

Kubernetes 版本:1.23.14+k3s。

要求:在

node3
node4上部署2我的PostgreSQL Pod(主/从)。

我用以下标记和污染了 node3node4

kubectl label nodes node3 type=postgres
kubectl label nodes node4 type=postgres
kubectl taint nodes node3 type=postgres:NoSchedule
kubectl taint nodes node4 type=postgres:NoSchedule

这是我的节点及其标签(注意 NODE3/4 上的 type=postgres

NAME   STATUS   ROLES                  AGE   VERSION         LABELS
node1   Ready    control-plane,master        v1.23.14+k3s1   ......................
node2   Ready    <none>                      v1.23.14+k3s1   ......................
node3   Ready    <none>                      v1.23.14+k3s1   kubernetes.io/hostname=node3,kubernetes.io/os=linux,node.kubernetes.io/instance-type=k3s,type=postgres
node4   Ready    <none>                      v1.23.14+k3s1   kubernetes.io/hostname=node4,kubernetes.io/os=linux,node.kubernetes.io/instance-type=k3s,type=postgres

这是我在 PostgreSQL 部署中使用的 Affinity:

    tolerations:
    - key: "type"
      operator: "Equal"
      value: "postgres"
      effect: "NoSchedule"
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
          - matchExpressions:
              - key: type
                operator: In
                values:
                  - postgres

现在的问题是,当我部署整个命名空间及其所有 Pod 时,

PG
(Postgres)Pod(主/从)被部署到
node1/node2
并且没有部署任何内容
node3/node4

事件表明:

0/4 nodes are available: 2 Insufficient memory, 2 node(s) had taint {type: postgres}, that the pod didn't tolerate.

为什么会出现这种情况?

postgresql kubernetes kubectl k3s
1个回答
0
投票

由于您污染了 2 个节点,因此调度程序在尝试调度 pod 时不会考虑它们。

nodeAffinity 可以帮助您过滤可以调度 pod 的节点,但同样,污点会告诉调度程序丢弃它们。

您必须告诉调度程序您的 Pod 能够容忍污染,并且您可以通过容忍来做到这一点:

    tolerations:
    - key: "type"
        operator: "Equal" 
        effect: "NoSchedule"
        value: "postgres"
© www.soinside.com 2019 - 2024. All rights reserved.