k8s中污点 (tain) 和容忍 (tolerations)

污点就是拒绝,容忍就是忽略,Node通过污点拒绝pod调度上去,Pod通过容忍忽略拒绝

污点:给节点添加

污点的格式为: key=value:effect , key和value是污点的标签,effect描述污点的作用,支持如下三个

选项:

effect描述污点的作用
NoSchedulekubernetes将不会把Pod调度到具有该污点的Node上,但不会影响当前Node上已存在的Pod
NoExecutekubernetes将不会把Pod调度到具有该污点的Node上,同时也会将Node上已存在的Pod驱离
PreferNoSchedulekubernetes将尽量避免把Pod调度到具有该污点的Node上,除非没有其他节点可调度
#添加污点
[root@k8s-master1 xmgc1]# kubectl taint node k8s-node1 tag=xmgc:NoSchedule
node/k8s-node1 tainted

#删除污点
[root@k8s-master1 xmgc1]# kubectl taint node k8s-node1 tag:NoSchedule-
node/k8s-node1 untainted

查询污点:

[root@k8s-master1 xmgc1]# kubectl describe node k8s-node1
Name:               k8s-node1
Roles:              jenkins,node
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/arch=amd64
                    kubernetes.io/hostname=k8s-node1
                    kubernetes.io/os=linux
                    node-role.kubernetes.io/jenkins=
                    node-role.kubernetes.io/node=node1
Annotations:        flannel.alpha.coreos.com/backend-data: {"VNI":1,"VtepMAC":"f6:9f:ac:eb:0e:8d"}
                    flannel.alpha.coreos.com/backend-type: vxlan
                    flannel.alpha.coreos.com/kube-subnet-manager: true
                    flannel.alpha.coreos.com/public-ip: 192.168.198.146
                    kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
                    node.alpha.kubernetes.io/ttl: 0
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Fri, 12 Aug 2022 17:53:47 +0800
Taints:             tag=xmgc:NoSchedule
Unschedulable:      false
Lease:

容忍:给pod添加

我们可以在node上添加污点用于拒绝pod调度上来,但是如果就是想将一个pod调度到一个有污点的node上去,这时候应该怎么做呢?这就要使用到容忍

创建pod-toleration.yaml,内容如下:

apiVersion: v1

kind: Pod

metadata:

  name: pod-toleration

  namespace: dev

spec:

  containers:

  - name: nginx

  image: nginx:1.17.1

  tolerations: # 添加容忍

    - key: "tag" # 要容忍的污点的keyoperator: "Equal" # 操作符

    value: "xmgc" # 容忍的污点的value

    effect: "NoSchedule" # 添加容忍的规则,这里必须和标记的污点规则相同

原文连接:https://www.dianjilingqu.com/541777.html

本文章来源于网络,版权归原作者所有,如果本文章侵犯了您的权益,请联系删除,感谢支持理解。

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐