Kubernetes(k8s)的调度器 - 调度亲和性详细介绍
发布日期:2021-05-07 16:38:39 浏览次数:26 分类:技术文章

本文共 2873 字,大约阅读时间需要 9 分钟。

节点亲和性

pod.spec.nodeAffinity

  • preferredDuringSchedulingIgnoredDuringExecution:软策略
  • requiredDuringSchedulingIgnoredDuringExecution:硬策略

requiredDuringSchedulingIgnoredDuringExecution

apiVersion: v1kind: Podmetadata:  name: affinity  labels:    app: node-affinity-podspec:  containers:  - name: with-node-affinity    image: wangyanglinux/myapp:v1  affinity:    nodeAffinity:      requiredDuringSchedulingIgnoredDuringExecution:        nodeSelectorTerms:        - matchExpressions:          - key: kubernetes.io/hostname            operator: NotIn            values:            - node02

preferredDuringSchedulingIgnoredDuringExecution

apiVersion: v1kind: Podmetadata:  name: affinity  labels:    app: node-affinity-podspec:  containers:  - name: with-node-affinity    image: wangyanglinux/myapp:v1  affinity:    nodeAffinity:      preferredDuringSchedulingIgnoredDuringExecution:      - weight: 1        preference:          matchExpressions:          - key: kubernetes.io/hostname            operator: In            values:            - node3

先硬后软

apiVersion: v1kind: Podmetadata:  name: affinity  labels:    app: node-affinity-podspec:  containers:  - name: with-node-affinity    image: hub.atguigu.com/library/myapp:v1  affinity:    nodeAffinity:      requiredDuringSchedulingIgnoredDuringExecution:        nodeSelectorTerms:        - matchExpressions:          - key: kubernetes.io/hostname            operator: NotIn            values:            - k8s-node02      preferredDuringSchedulingIgnoredDuringExecution:      - weight: 1        preference:          matchExpressions:          - key: source            operator: In            values:            - qikqiak

键值运算关系

  • In:label 的值在某个列表中
  • NotIn:label 的值不在某个列表中
  • Gt:label 的值大于某个值
  • Lt:label 的值小于某个值
  • Exists:某个 label 存在
  • DoesNotExist:某个 label 不存在
     

 Pod  亲和性

pod.spec.affinity.podAffinity/podAntiAffinity

  • preferredDuringSchedulingIgnoredDuringExecution:软策略
  • requiredDuringSchedulingIgnoredDuringExecution:硬策略
apiVersion: v1kind: Podmetadata:  name: pod-3  labels:    app: pod-3spec:  containers:  - name: pod-3    image: wangyanglinux/myapp:v1  affinity:    podAffinity:      requiredDuringSchedulingIgnoredDuringExecution:      - labelSelector:          matchExpressions:          - key: app            operator: In            values:            - pod-1        topologyKey: kubernetes.io/hostname    podAntiAffinity:      preferredDuringSchedulingIgnoredDuringExecution:      - weight: 1        podAffinityTerm:          labelSelector:            matchExpressions:            - key: app              operator: In              values:              - pod-2          topologyKey: kubernetes.io/hostname

亲和性/反亲和性调度策略比较如下:

 

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

 

上一篇:Centos7使用脚本搭建LVS的DR模式。
下一篇:Kubernetes(k8s)的调度器详细介绍

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2025年04月09日 21时27分18秒