k8s----节点亲和性和污点容忍

1、查看标签
kubectl  get nodes --show-labels

2、打标签
kubectl label nodes node1.com kong=true 
kubectl label nodes node2.com kong=true 
kubectl label nodes node3.com kong=true

3、node添加亲和性
spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: kong
                operator: In
                values:
                - "true"
4、删除label
kubectl label nodes node1.com kong-

 

反亲和性

affinity:
  podAntiAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
    - weight: 100
      podAffinityTerm:
        labelSelector:
          matchExpressions:
           - key: k8s-app
             operator: In
             values:
             - my-app
        topologyKey: kubernetes.io/hostname

 

 

节点绑定 
    spec:
      containers:
      dnsPolicy: ClusterFirst
      nodeSelector:
        kubernetes.io/hostname: node03.paas

 

污点和容忍

NoSchedule:表示 pod 不会被调度到标记为 taints 的节点,只会影响新的 pod 调度
PreferNoSchedule:NoSchedule 的软策略版本,表示尽量不调度到污点节点上去,只会影响新的 pod 调度
NoExecute:该选项意味着一旦 Taint 生效,如该节点内正在运行的 pod 没有对应 Tolerate 设置,会直接被逐出

# 节点添加污点
$ kubectl taint nodes node02 xiangmu=install:NoSchedule
# 取消节点污点
 kubectl taint nodes node02 xiangmu-
# 查看节点污点
kubectl describe nodes node02|grep Taints
如果 operator 的值是 Exists,则 value 属性可省略 如果 operator 的值是 Equal,则表示其 key 与 value 之间的关系是 equal(等于) 如果不指定 operator 属性,则默认值为 Equal 如果pod想部署到此节点,需要添加如下内容 spec: containers: - name: nginx image: nginx:1.7.9 tolerations: - key: "app" operator: "Exists" effect: "NoSchedule" #这里的值要和上面的的添加污点的值匹配上,不然调度不到

重要:如果只调度到此污点节点,pod还需要添加如下亲和性
kubectl  label node yq-map app=my-map
affinity:
  podAntiAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
    - weight: 100
      podAffinityTerm:
        labelSelector:
          matchExpressions:
           - key: app
             operator: In
             values:
             - my-app
 

 参考:https://blog.csdn.net/qq_34556414/article/details/109448632

posted @ 2020-07-23 10:14  凯文队长  阅读(1117)  评论(0编辑  收藏  举报