码迷,mamicode.com
首页 > Web开发 > 详细

[kubernetes集群调度] - ② 调度亲和性

时间:2020-05-23 00:28:20      阅读:64      评论:0      收藏:0      [点我收藏+]

标签:note   nta   pod   拓扑   index   ssi   支持   container   hostname   

节点亲和性

pod.spec.nodeAffinity:

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

requiredDuringSchedulingIgnoredDuringExecution:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
apiVersion: v1
kind: Pod
metadata:
 name: affinity
 labels:
   app: node-affinity-pod
spec:
 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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
apiVersion: v1
kind: Pod
metadata:
 name: affinity
 labels:
  app: node-affinity-pod
spec:
 containers:
 - name: with-node-affinity
  image: hub.atguigu.com/library/myapp:v1
 affinity:
  nodeAffinity: <br>   preferredDuringSchedulingIgnoredDuringExecution:
   - weight: 1
    preference:
     matchExpressions:
     - key: source
     operator: In
     values:
     - qikqiak

合体

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
apiVersion: v1
kind: Pod
metadata:
 name: affinity
 labels:
  app: node-affinity-pod
spec:
 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:硬策略
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
apiVersion: v1
kind: Pod
metadata:
 name: pod-3
 labels:
  app: pod-3
spec:
 containers:
 - name: pod-3
  image: hub.atguigu.com/library/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不在同
一拓扑域

 

[kubernetes集群调度] - ② 调度亲和性

标签:note   nta   pod   拓扑   index   ssi   支持   container   hostname   

原文地址:https://www.cnblogs.com/uvwill/p/12940478.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!