Taints

一、节点的污点(Taints)

点是附加到节点上的一组键值对,用于指示节点的一些特性或者状态。污点可以防止不符合条件的 Pod 被调度到该节点上。

污点的格式为 key=value:effect

  • key:污点的键。

  • value:污点的值(可选)。

  • effect:污点的效果,可以是 NoSchedulePreferNoScheduleNoExecute

污点的类型

  1. NoSchedule:该节点不能调度新的 Pod,如果 Pod 不具有对应的容忍度。

  2. PreferNoSchedule:该节点尽量不调度新的 Pod,但如果没有其他合适的节点,也可以调度。

  3. NoExecute:该节点上已经运行的 Pod 将被驱逐,新的 Pod 不能调度到该节点上,除非 Pod 具有对应的容忍度。

标记污点
#示例:node1 的节点添加了一个污点,表示如果 Pod 没有对应的容忍度,将不能被调度到该节点。
kubectl taint nodes node1 key=value:NoSchedule

查看污点

kubectl describe node node1 | grep Taints

删除污点

kubectl taint node node1key=value:NoSchedule-

二、Pod 的容忍度(Tolerations)

容忍度是附加到 Pod 上的一组规则,用于指示 Pod 可以容忍哪些污点。这允许 Pod 在特定污点的节点上运行。

tolerations:
- key: "<key>"
  operator: "<operator>"
  value: "<value>"
  effect: "<effect>"
  tolerationSeconds: <seconds>
  • key:与节点污点的键匹配。

  • operator:操作符,通常是 EqualExists

  • value:与节点污点的值匹配(可选)。

  • effect:污点的效果,可以是 NoSchedulePreferNoScheduleNoExecute

  • tolerationSeconds:适用于 NoExecute,指定 Pod 可以容忍污点的时间(秒),超时后将被驱逐(可选)

#示例  Pod my-pod 将容忍键为 key 且值为 value 的污点,且效果是 NoSchedule。这意味着即使节点上有这样的污点,Pod 仍然可以调度到该节点上。
apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  tolerations:
  - key: "key"
    operator: "Equal"
    value: "value"
    effect: "NoSchedule"

三、总结

  • 节点污点(Taints):用于标记节点的特殊条件,防止不符合条件的 Pod 被调度到节点上。

  • Pod 容忍度(Tolerations):用于标记 Pod 可以容忍哪些污点,从而允许 Pod 在具有这些污点的节点上运行。

#示例:node节点污点
vim replicaset.yaml

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: my-replicaset
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      nodeSelector:
        nodemaster: "yes"
      containers:
       - name: mycontainer
         image: harbor.hiuiu.com/nginx/nginx:1.21.5
         imagePullPolicy: Never
         ports:
         - containerPort: 80
      tolerations:
        - key: "disk-type"
          operator: "Equal"
          value: "IDE"
          effect: "NoSchedule"

kubectl taint node hx5 disk-type=IDE:NoSchedule
kubectl taint node hx6 disk-type=IDE:NoExecute
kubectl describe node hx5 | grep Taints
kubectl describe node hx6 | grep Taints
kubectl apply -f replicaset.yaml
kubectl get pod -o wide

 

posted @ 2024-08-22 17:31  hx_ky36  阅读(1)  评论(0编辑  收藏  举报