首页
视频
资源
登录
原
Kubernetes DaemonSet讲解
6230
人阅读
2021/3/4 10:00
总访问:
2615350
评论:
0
收藏:
0
手机
分类:
容器编排
![Kubernetes](https://img.tnblog.net/arcimg/hb/274ef6f115de4c9b8e40ded5deb2f4c2.jpg "Kubernetes") >#Kubernetes DaemonSet讲解 [TOC] 需求来源 ------------ ### 背景问题 <p style=" font-weight: 400; line-height: 1.5; color: #212529; -webkit-tap-highlight-color: transparent; box-sizing: border-box; padding: 0px 20px 20px 20px; border: 1px solid #e9ecef; border-left-width: .25rem; border-radius: .25rem; display: block; border-left-color: #5bc0de;"> 我们可以让每个集群内的节点都运行一个相同的Pod吗? 如果这样做,以下的问题有什么方式来解决: 1. 我们如何保证每个节点都运行一个Pod? 2. 如果新节点加入集群,如何感知并部署对应的Pod? 3. 如果有节点退出,如何删除对应的Pod? 4. 如果Pod状态异常,如何监控并恢复Pod的状态? </p> ### DaemonSet 守护进程控制器 <p style=" font-weight: 400; line-height: 1.5; color: #212529; -webkit-tap-highlight-color: transparent; box-sizing: border-box; padding: 0px 20px 20px 20px; border: 1px solid #e9ecef; border-left-width: .25rem; border-radius: .25rem; display: block; border-left-color: #5bc0de;"> DaemonSet 能帮助我们做什么事情? 1. 保证集群内每一个(或一些节点)都运行一组相同的Pod 2. 跟踪集群节点状态,保证新加入的节点自动创建对应的Pod 3. 跟踪集群节点状态,保证移除的节点删除对应的Pod 4. 跟踪Pod状态,保证每个节点Pod处于运行状态 </p> 用例解读 ------------ ### DaemonSet 语法 <p style=" font-weight: 400; line-height: 1.5; color: #212529; -webkit-tap-highlight-color: transparent; box-sizing: border-box; padding: 0px 20px 20px 20px; border: 1px solid #e9ecef; border-left-width: .25rem; border-radius: .25rem; display: block; border-left-color: #5bc0de;"> 适用场景: 1. 集群存储进程:glusterd,ceph 2. 日志收集进程:fluentd,logstash 3. 需要在每个节点运行的监控收集器 </p> DaemonSet-Demo.yaml ```yaml apiVersion: apps/v1 kind: DaemonSet metadata: name: fluentd-elasticsearch labels: k8s-app: fluentd-logging spec: selector: matchLabels: name: fluentd-elasticsearch template: metadata: labels: name: fluentd-elasticsearch spec: tolerations: - key: node-role.kubernetes.io/master effect: NoSchedule containers: - name: fluentd-elasticsearch image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2 resources: limits: memory: 200Mi requests: cpu: 100m memory: 200Mi volumeMounts: - name: varlog mountPath: /var/log - name: varlibdockercontainers mountPath: /var/lib/docker/containers readOnly: true terminationGracePeriodSeconds: 30 volumes: - name: varlog hostPath: path: /var/log - name: varlibdockercontainers hostPath: path: /var/lib/docker/containers ``` ### 查看DaemonSet状态 ```bash # kubectl get ds NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE fluentd-elasticsearch 1 1 1 1 1 <none> 13s # kubectl get pods NAME READY STATUS RESTARTS AGE fluentd-elasticsearch-b2t7l 1/1 Running 0 19s ``` <p style=" font-weight: 400; line-height: 1.5; color: #212529; -webkit-tap-highlight-color: transparent; box-sizing: border-box; padding: 0px 20px 20px 20px; border: 1px solid #e9ecef; border-left-width: .25rem; border-radius: .25rem; display: block; border-left-color: #5bc0de;"> 状态描述:(本集群公有一个节点[所以大家可以多弄几个节点]) - **DESIRED: 需要的Pod个数** - **UP-TO-DATE: 最新创建的个数** - **CURRENT: 当前已存在的pod个数** - **AVAILABLE: 可用pod个数** - **READY: 就绪的个数** - **NODE SELECTOR: 节点选择标签** </p> ### 更新DaemonSet <p style=" font-weight: 400; line-height: 1.5; color: #212529; -webkit-tap-highlight-color: transparent; box-sizing: border-box; padding: 0px 20px 20px 20px; border: 1px solid #e9ecef; border-left-width: .25rem; border-radius: .25rem; display: block; border-left-color: #5bc0de;"> 更新策略: 1. RollingUpdate: DaemonSet默认更新策略,当更新DaemonSet模板后,老的Pod会被先删除,然后再去创建新的Pod,可以配合健康检查做滚动更新。 2. OnDelete: 当DaemonSet模板更新后,只有手动的删除某一个对应的Pod,此节点Pod才会被更新。 </p> ```bash # 更新镜像 # kubectl set image ds/fluentd-elasticsearch fluentd-elasticsearch=fluent/fluentd:v1.4 daemonset.extensions/fluentd-elasticsearch image updated # kubectl rollout status ds/fluentd-elasticsearch Waiting for daemon set "fluentd-elasticsearch" rollout to finish: 0 out of 1 new pods have been updated... Waiting for daemon set "fluentd-elasticsearch" rollout to finish: 0 of 1 updated pods are available... daemon set "fluentd-elasticsearch" successfully rolled out ``` 架构设计 ------------ <p style=" font-weight: 400; line-height: 1.5; color: #212529; -webkit-tap-highlight-color: transparent; box-sizing: border-box; padding: 0px 20px 20px 20px; border: 1px solid #e9ecef; border-left-width: .25rem; border-radius: .25rem; display: block; border-left-color: #5bc0de;"> 1. DaemonSet Controller 负责根据配置创建Pod 2. DaemonSet Controller 跟踪Job状态,更加配置及时重试Pod或者继续创建 3. DaemonSet Controller 会自动添加affinity & label来跟踪对应的pod,并根据配置在每个节点或者适合的部分节点创建Pod </p> ![](https://img.tnblog.net/arcimg/hb/58267c99893f40fd965e10c4aaa90c6c.png)
欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739
👈{{preArticle.title}}
👉{{nextArticle.title}}
评价
{{titleitem}}
{{titleitem}}
{{item.content}}
{{titleitem}}
{{titleitem}}
{{item.content}}
尘叶心繁
这一世以无限游戏为使命!
博主信息
排名
6
文章
6
粉丝
16
评论
8
文章类别
.net后台框架
168篇
linux
17篇
linux中cve
1篇
windows中cve
0篇
资源分享
10篇
Win32
3篇
前端
28篇
传说中的c
4篇
Xamarin
9篇
docker
15篇
容器编排
101篇
grpc
4篇
Go
15篇
yaml模板
1篇
理论
2篇
更多
Sqlserver
4篇
云产品
39篇
git
3篇
Unity
1篇
考证
2篇
RabbitMq
23篇
Harbor
1篇
Ansible
8篇
Jenkins
17篇
Vue
1篇
Ids4
18篇
istio
1篇
架构
2篇
网络
7篇
windbg
4篇
AI
18篇
threejs
2篇
人物
1篇
嵌入式
2篇
python
13篇
HuggingFace
8篇
pytorch
9篇
opencv
6篇
Halcon
1篇
最新文章
最新评价
{{item.articleTitle}}
{{item.blogName}}
:
{{item.content}}
关于我们
ICP备案 :
渝ICP备18016597号-1
网站信息:
2018-2024
TNBLOG.NET
技术交流:
群号656732739
联系我们:
contact@tnblog.net
欢迎加群
欢迎加群交流技术