污点和容忍度taint tolerations

污点和容忍度taint tolerations
官方文档写的真的挺好:
https://kubernetes.io/zh/docs/concepts/scheduling-eviction/taint-and-toleration/

污点和容忍度

节点亲和性 是 Pod 的一种属性,它使 Pod 被吸引到一类特定的节点 (这可能出于一种偏好,也可能是硬性要求)。 污点(Taint)则相反——它使节点能够排斥一类特定的 Pod。

容忍度(Toleration)是应用于 Pod 上的,允许(但并不要求)Pod 调度到带有与之匹配的污点的节点上。

污点和容忍度(Toleration)相互配合,可以用来避免 Pod 被分配到不合适的节点上。 每个节点上都可以应用一个或多个污点,这表示对于那些不能容忍这些污点的 Pod,是不会被该节点接受的。

自己稍微小结一下,
给节点打污点:

您可以使用命令 kubectl taint 给节点增加一个污点。比如,

kubectl taint nodes node1 key1=value1:NoSchedule

去除污点

kubectl taint nodes node1 key1=value1:NoSchedule-

然后tolerations 作用于pod,分2中区别不大

tolerations:
- key: "key1"
  operator: "Equal"
  value: "value1"
  effect: "NoSchedule"
tolerations:
- key: "key1"
  operator: "Exists"
  effect: "NoSchedule"

operator 分Equal和Exists ,后者对应value为空的情况。

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    env: test
spec:
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent
  tolerations:
  - key: "example-key"
    operator: "Exists"
    effect: "NoSchedule"

上面就是value不存在的情况,operator用Exists。
真的有适用场景,就是想让节点上面只放某类应用,污点很好用,可以配合亲和性使用。

posted @ 2022-03-15 09:35  过去的我  阅读(130)  评论(0编辑  收藏  举报