1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
[root@k8s-master cka]# cat multi-expression-in-term.yaml apiVersion: v1 kind: Pod metadata: name: node-affinity-allmatch spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: role operator: In values: - master - key: role operator: In values: - node containers: - name: with-node-affinity image: nginx Warning FailedScheduling default-scheduler 0/2 nodes are available: 2 node(s) didn't match node selector. |
在一个matchexpression部分中的多条件是 AND关系
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[root@k8s-master cka]# cat multi-terms.yaml apiVersion: v1 kind: Pod metadata: name: node-affinity-ifany spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: role operator: In values: - master - matchExpressions: - key: role operator: In values: - node containers: - name: with-node-affinity image: nginx |
多nodeselectorterm是 或,任意一个匹配即可
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 30 31 32 33 |
[root@k8s-master cka]# cat prefer-affinity.yaml apiVersion: v1 kind: Pod metadata: name: node-affinity-ifany spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: owner operator: In values: - lj preferredDuringSchedulingIgnoredDuringExecution: - weight: 10 preference: matchExpressions: - key: role operator: In values: - node containers: - name: with-node-affinity image: nginx 2018-08-11 13:17:44 +0800 CST 2018-08-11 13:17:44 +0800 CST 1 node-affinity-ifany.1549bcbc3b670aef Pod Normal Scheduled default-scheduler Successfully assigned node-affinity-ifany to k8s-node1 2018-08-11 13:17:45 +0800 CST 2018-08-11 13:17:45 +0800 CST 1 node-affinity-ifany.1549bcbc733d4529 Pod Normal SuccessfulMountVolume kubelet, k8s-node1 MountVolume.SetUp succeeded for volume "default-token-gt88m" 2018-08-11 13:17:47 +0800 CST 2018-08-11 13:17:47 +0800 CST 1 node-affinity-ifany.1549bcbcd5bfb3af Pod spec.containers{with-node-affinity} Normal Pulling kubelet, k8s-node1 pulling image "nginx" 2018-08-11 13:17:55 +0800 CST 2018-08-11 13:17:55 +0800 CST 1 node-affinity-ifany.1549bcbecd747893 Pod spec.containers{with-node-affinity} Normal Pulled kubelet, k8s-node1 Successfully pulled image "nginx" 2018-08-11 13:17:55 +0800 CST 2018-08-11 13:17:55 +0800 CST 1 node-affinity-ifany.1549bcbeda6e3ece Pod spec.containers{with-node-affinity} Normal Created kubelet, k8s-node1 Created container 2018-08-11 13:17:56 +0800 CST 2018-08-11 13:17:56 +0800 CST 1 node-affinity-ifany.1549bcbee47f163c Pod spec.containers{with-node-affinity} Normal Started kubelet, k8s-node1 Started container |
required首先要满足,在同时多个node满足的情况下,使用prefer,preference下只能配置一个matchexpression,如果匹配则给node加weight(因为此时scheduler还需根据很多其它条件来排序可用的nodes,增加分值可以增加选择概率)
Taints, 用在node上,格式为key=value:effect,例如
edge=true:NoSchedule
gpu=true:NoSchedule
bigdata=true:NoExcute
dev=team3:PreferNoSschedule
最后的effect指明了这个taint的动作,拒绝被调度,拒绝pod在其上执行,不优先考虑被调度。如果一个node有了Noschedule的taint,那么只有当pod声明了对应的key/value/effect的tolerations时,这个pod才可以被调度到这个node上。
所以这个方法一般用来保护一个node,确保node上只调度那些期望的pods。
一个node包含多个taints,tolerations会挨个根据自己的tolerations去匹配过滤,都能被toleration了就可以调度,如果有剩余的taints没被匹配,那么根据这个剩余的taints本身的效果来决定。
1 2 3 |
tolerations: - key: "key" operator: "Exists"</code> 匹配key的任意effect都可以被容忍 |
1 2 3 |
tolerations: - operator: "Exists" 表示容忍所有。 Existsccc操作本身不需要配置value |
文章评论