添加污点的Node节点默认不会参与日常调度,有两种策略分别为“NoSchedule”和“NoExecute”,加入污点的Node只有在Pod的Yaml文件设置相对应的容忍,Pod才会调度到该节点,

NoSchedule:软策略,表示尽量不调度到污点节点上去,只会影响到新的pod而不会对已经运行在该Node节点其他pod造成影响;;;;;Node节点上的旧Pod不会被驱逐
NoExecute:该选项意味着一旦 Taint 生效,如该节点内正在运行的 pod 没有对应 Tolerate 设置,会直接被逐出

NoSchedule

#添加污点到Node节点上
kubectl taint node k8s-03 test=k8s-03:NoSchedule
#查看Node节点污点
kubectl describe node k8s-03

 

#创建测试Pod的yaml

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: taint
  labels:
    app: taint
spec:
  replicas: 3
  revisionHistoryLimit: 10
  template:
    metadata:
      labels:
        app: taint
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - name: http
          containerPort: 80
      tolerations:                    #添加容忍
      - key: "test"
        operator: "Equal"  #"Equal"表示key与value之间的关系是等于
        value: "k8s-03"
        effect: "NoSchedule"

结果:原来该Node上的Pod并没有被驱逐,创建没有与该Node污点对应容忍的Pod不会调度到该节点

NoExecute

在给Node节点添加污点后,Node节点上的旧Pod会被驱逐

这里配合调度亲和性的硬策略,可以实现deployment/statefulset下面所有的pod只运行在该节点上,且该节点不参与普通调度旧Pod被驱逐

#Node添加污点
kubectl taint node k8s-04 ceshi=ceshi:NoExecute
#查看Node节点污点
kubectl describe node k8s-04



#创建测试Pod的yaml

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: taint
  labels:
    app: taint
spec:
  replicas: 3
  revisionHistoryLimit: 10
  template:
    metadata:
      labels:
        app: taint
    spec:
      affinity:    #指定调度亲和性
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:  #调度硬策略
            nodeSelectorTerms:
              - matchExpressions:      #指定标签,可以写其他该Node的唯一标签
                - key: kubernetes.io/hostname
                  operator: In
                  values:
                  - k8s-04
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - name: http
          containerPort: 80
      tolerations:                    #指定容忍策略
      - key: "ceshi"
        operator: "Equal"
        value: "ceshi"
        effect: "NoExecute"
结果:

所有的Pod都被调度到了有污点的Node(k8s-04)上,且创建普通pod不会考虑调度到该Node节点上

Logo

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

更多推荐