wittyResry / myIssue

My issue mark down^_^ 欢迎吐槽,讨论~~
https://github.com/wittyResry/myIssue/issues
The Unlicense
5 stars 1 forks source link

k8s schedule调度策略 #142

Open wittyResry opened 2 years ago

wittyResry commented 2 years ago

https://blog.csdn.net/weixin_46686835/article/details/115103098?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166433334316782388036914%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=166433334316782388036914&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-115103098-null-null.142^v50^control,201^v3^control_2&utm_term=k8s%20schedule&spm=1018.2226.3001.4187

wittyResry commented 2 years ago

节点亲和性-pod.spec.nodeAffinity requiredDuringSchedulingIgnoredDuringExecution:硬策略 硬策略指的是强制性的,必须匹配或必须不匹配 preferredDuringSchedulingIgnoredDuringExecution:软策略 软策略指的是尽量匹配,如果没有匹配也没有关系

Pod 亲和性–pod.spec.affinity.podAffinity/podAntiAffinity

调度策略 匹配标签 操作符 拓扑域支持 调度目标 nodeAffinity 主机 In, NotIn, Exists, DoesNotExist, Gt, Lt 否 指定主机 podAffinity POD In, NotIn, Exists, DoesNotExist 是 POD与指定POD同一拓扑域 podAnitAffinity POD In, NotIn, Exists, DoesNotExist 是 POD与指定POD不在同一拓扑域

Taint(污点)和 Toleration(容忍)

节点亲和性,是pod的一种属性(偏好或硬性要求),它使pod被吸引到一类特定的节点。Taint 则相反,它使节点能够 排斥 一类特定的 pod

Taint 和 toleration 相互配合,可以用来避免 pod 被分配到不合适的节点上。每个节点上都可以应用一个或多个 taint ,这表示对于那些不能容忍这些 taint 的 pod,是不会被该节点接受的。如果将 toleration 应用于 pod 上,则表示这些 pod 可以(但不要求)被调度到具有匹配 taint 的节点上(默认都不会容忍污点)

每个污点的组成如下:key=value:effect, effect包含NoSchedule(不调度),PreferNoSchedule(尽量不调度),NoExecute(驱逐)

# 设置污点
kubectl taint nodes node1 key1=value1:NoSchedule

# 节点说明中,查找 Taints 字段
kubectl describe pod  pod-name  

# 去除污点
kubectl taint nodes node1 key1:NoSchedule-

容忍(道高一尺,魔高一丈,有污点就有容忍)

tolerations:
- key: "key1"  
  operator: "Equal"
  value: "value1"
  effect: "NoSchedule"  # 容忍的key是key1,value值是value1,策略是NoSchedule,也就是说,这样的污点可以被容忍,pod可能会向有这个污点的node上分配(不一定肯定会分配,有分配的可能)
  tolerationSeconds: 3600
- key: "key1"
  operator: "Equal"
  value: "value1"
  effect: "NoExecute"
- key: "key2"
  operator: "Exists"
  effect: "NoSchedule"