Cloud Native应用交付

  • 首页
  • 关于本站
  • 个人介绍
  • Downloads
  • Repo
    • Github
    • Container
  • F5
    • F5 Python SDK
    • F5-container
    • F5-LBaaS
  • 社交
    • 联系我
    • 微信/微博
    • 公众号
    • 打赏赞助
行至水穷处 坐看云起时
Cloud Native Application Services: cnadn.net
  1. 首页
  2. 容器/k8s
  3. 正文

Node Affinity / Taints /Tolerations

2018年08月11日 7143点热度 0人点赞 0条评论

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

相关文章

  • 项目:k8s Gateway API 的BIG-IP实现
  • F5 CES 用融合的思想保护k8s出向流量安全
  • 是时候思考k8s出向流量安全了
  • Container Egress Services 容器出向流量策略管控
  • Service Account Token Volume Projection
本作品采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可
标签: affinity k8s taints toleration 亲和
最后更新:2018年08月11日

纳米

linjing.io

打赏 点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理。

页面AI聊天助手

纳米

linjing.io

☁️迈向Cloud Native ADC ☁️

认证获得:
TOGAF: ID 152743
Kubernetes: CKA #664
Microsoft: MCSE MCDBA
Cisco: CCNP
Juniper: JNCIS
F5:
F5 Certified Solution Expert, Security
F5 Certified Technology Specialist, LTM/GTM/APM/ASM
F5 Certified BIG-IP Administrator
  • 点击查看本博技术要素列表
  • 归档
    分类
    • AI
    • Automation
    • Avi Networks
    • Cisco ACI
    • CISCO资源
    • F5 with ELK
    • F5-Tech tips
    • F5技术
    • Juniper
    • Linux
    • NGINX
    • SDN
    • ServiceMesh
    • WEB编程
    • WINDOWS相关
    • 业界文章
    • 交换机技术
    • 化云为雨/Openstack
    • 协议原理
    • 容器/k8s
    • 我的工作
    • 我的生活
    • 网站技术
    • 路由器技术
    • 项目案例
    标签聚合
    F5 flannel istio nginx openstack api gtm DNS k8s docker network envoy bigip neutron irule
    最近评论
    汤姆 发布于 8 个月前(09月10日) 嗨,楼主,里面的json怎么下载啊,怎么收费啊?
    汤姆 发布于 8 个月前(09月09日) 大佬,kib的页面可以分享下吗?谢谢
    zhangsha 发布于 1 年前(05月12日) 资料发给我下,谢谢纳米同志!!!!lyx895@qq.com
    李成才 发布于 1 年前(01月02日) 麻烦了,谢谢大佬
    纳米 发布于 1 年前(01月02日) 你好。是的,因为以前下载系统插件在一次升级后将所有的下载生成信息全弄丢了。所以不少文件无法下载。DN...
    浏览次数
    • Downloads - 183,766 views
    • 联系我 - 118,966 views
    • 迄今为止最全最深入的BIGIP-DNS/GTM原理及培训资料 - 116,497 views
    • Github - 103,655 views
    • F5常见log日志解释 - 79,774 views
    • 从传统ADC迈向CLOUD NATIVE ADC - 下载 - 74,623 views
    • Sniffer Pro 4 70 530抓包软件 中文版+视频教程 - 74,320 views
    • 迄今为止最全最深入的BIGIP-DNS/GTM原理及培训资料 - 67,770 views
    • 关于本站 - 60,905 views
    • 这篇文档您是否感兴趣 - 55,493 views
    链接表
    • F5SE创新
    • Jimmy Song‘s Blog
    • SDNlab
    • Service Mesh社区
    • 三斗室
    • 个人profile
    • 云原生社区

    COPYRIGHT © 2023 Cloud Native 应用交付. ALL RIGHTS RESERVED.

    Theme Kratos Made By Seaton Jiang

    京ICP备14048088号-1

    京公网安备 11010502041506号