当前位置: 首页 > news >正文

DaemonSet使用示例

在 Kubernetes 中创建 DaemonSet 资源时,通过 nodeSelector 、affinity 等配置来规定在每个节点运行或是在部分节点运行:

让 DaemonSet 在每个节点运行

默认情况下,如果不做任何特殊的节点选择配置,DaemonSet 会在集群中的每个符合条件(比如节点能正常调度 Pod ,没有被设置 NoSchedule 等污点)的工作节点上运行一个 Pod 副本。以下是一个简单的 DaemonSet YAML 示例:

yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:name: nginx-daemonset
spec:selector:matchLabels:app: nginx-daemonsettemplate:metadata:labels:app: nginx-daemonsetspec:containers:- name: nginximage: nginxports:- containerPort: 80

上述 YAML 中,没有对节点选择进行额外配置,此时 DaemonSet 会尝试在每个合适的工作节点上创建并运行一个包含 nginx 容器的 Pod 。

让 DaemonSet 在部分节点运行

1. 使用 nodeSelector

nodeSelector 是一种简单的节点选择方式,通过匹配节点上的标签来决定在哪些节点上运行 Pod 。假设集群中的部分节点有 role=webserver 这样的标签,想让 DaemonSet 只在这些节点上运行,可以这样配置:

yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:name: nginx-daemonset
spec:selector:matchLabels:app: nginx-daemonsettemplate:metadata:labels:app: nginx-daemonsetspec:nodeSelector:role: webserver  # 只在具有role=webserver标签的节点上运行containers:- name: nginximage: nginxports:- containerPort: 80

在上述配置中,nodeSelector.role: webserver 会使得 DaemonSet 仅在带有 role=webserver 标签的节点上创建 Pod 。

2. 使用 affinity(亲和性)

亲和性分为节点亲和性(nodeAffinity )和 Pod 亲和性与反亲和性,其中节点亲和性可以更灵活地选择节点。

  • 硬亲和性(requiredDuringSchedulingIgnoredDuringExecution):表示必须满足指定的条件,Pod 才会被调度到相应节点。例如:

yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:name: nginx-daemonset
spec:selector:matchLabels:app: nginx-daemonsettemplate:metadata:labels:app: nginx-daemonsetspec:affinity:nodeAffinity:requiredDuringSchedulingIgnoredDuringExecution:nodeSelectorTerms:- matchExpressions:- key: disktypeoperator: Invalues:- ssd  # 只在标签disktype值为ssd的节点上运行containers:- name: nginximage: nginxports:- containerPort: 80
  • 软亲和性(preferredDuringSchedulingIgnoredDuringExecution):表示尽量满足指定条件,但如果不满足,Pod 也可能会被调度到其他节点。比如:

yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:name: nginx-daemonset
spec:selector:matchLabels:app: nginx-daemonsettemplate:metadata:labels:app: nginx-daemonsetspec:affinity:nodeAffinity:preferredDuringSchedulingIgnoredDuringExecution:- weight: 100preference:matchExpressions:- key: regionoperator: Invalues:- us-west  # 优先在标签region值为us-west的节点上运行containers:- name: nginximage: nginxports:- containerPort: 80

此外,还可以结合污点(Taints)和容忍(Tolerations)来控制 Pod 能否被调度到特定节点 ,通过在 Pod 配置中设置容忍来允许 Pod 调度到带有特定污点的节点上,实现更精细的节点调度控制,让 DaemonSet 的 Pod 运行在符合要求的部分节点上。

http://www.dtcms.com/a/407489.html

相关文章:

  • 台州建网站北京装饰公司电话
  • docker容器的三大核心技术UnionFS(下)
  • 4.6 BRDF
  • Python GIL全局解释器锁技术演进
  • 小学老师在哪个网站做ppt做羊毛毡的网站
  • 模块化神经网络
  • Python多线程:让程序 “多线作战” 的秘密武器
  • 黟县方坑岭影视基地三剧连拍开机 《生死制暴》影视赋能乡村振兴
  • 微信网站打不开海南搜索引擎优化
  • 国产化(银河麒麟_海光CPU)消息中间件选型及安装
  • 宁波品牌网站推广优化公司章丘营销型网站设计公司
  • p6spy 打印完整sql
  • 【ARM】MDK-Functions界面设置
  • 沈阳市建设局网站首页网站的运行与维护
  • 昌宁县住房和城乡建设网站订阅号做流量 那些电影如何链接网站
  • 【LVS入门宝典】LVS调度算法轮询(RR)深度解析:从原理到实战的公平调度之道
  • udhcpc, udhcpd由 BusyBox编译出来就好
  • 前端 CORS 深度解析
  • HT81696 概述
  • PMP-项目管理-PMBOK第六版_中文版:引论
  • 上海网站建站建设自己做的网站在百度怎么发布
  • SpringBoot+QQ 邮箱邮件开发指南:环境配置、功能实现、异常处理一站式搞定
  • Linux 数据库 Mysql8 主从复制
  • 做网站的图片房产国内免费推广网站
  • 建设网站需要分析什么条件云南软件开发项目管理
  • OpenHands+cpolar:AI编程助手的远程调试新方案
  • 从 0 到 1 掌握 ESP32 RMT(新手友好版)
  • 做设计什么网站可以兼职网站管理与建设总结
  • 少样本学习学习论文分享:多模态性帮助单模态性
  • 深入MySQL底层2-SQL优化与数据库运维管理