【云原生 从零开始学Kubernetes】二十四、kubernetes控制器Daemonset_daemonset deployment(3)

img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以戳这里获取

updateStrategy #daemonset 的升级策略

#查看 DaemonSet 的 spec.template 字段如何定义
#对于 template 而言,其内部定义的就是 pod,pod 模板是一个独立的对象
[root@k8smaster ~]# kubectl explain ds.spec.template
kubectl explain ds.spec.template KIND: DaemonSet
VERSION: apps/v1

RESOURCE: template

FIELDS:
metadata
spec


### DaemonSet 使用案例:部署日志收集组件 fluentd



#master node1 node2 都下载 fluentd
#编写一个 DaemonSet 资源清单 daemonset 也是通过标签选择器来选择模板创建pod
[root@k8smaster ~]# mkdir ds
[root@k8smaster ~]# cd ds
[root@k8smaster ~]# kubectl explain ds.spec.template.spec.tolerations
#找到容忍度 Taints 因为没有定义value 下面定义容忍度也不用写值,写一个排斥等级就行了
[root@k8smaster ds]# vim daemonset.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
labels:
k8s-app: fluentd-logging
name: fluentd-elasticsearch
namespace: kube-system
spec:
selector:
matchLabels:
name: fluentd-elasticsearch
template:
metadata:
name: fluentd
labels:
name: fluentd-elasticsearch
spec:
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
containers:
- name: fluentd-elasticsearch
image: fluentd
resources:
limits:
memory: 500Mi
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
[root@k8smaster ds]# kubectl apply -f daemonset.yaml
daemonset.apps/fluentd-elasticsearch created
[root@k8smaster ds]# kubectl get ds -n kube-system
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
fluentd-elasticsearch 3 3 3 3 0 9s
kube-flannel-ds 3 3 3 3 3 18d
kube-proxy 3 3 3 3 3 kubernetes.io/os=linux 18d
[root@k8smaster ds]# kubectl get pods -n kube-system -o wide -l name=fluentd-elasticsearch
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
fluentd-elasticsearch-n5jj7 1/1 Running 0 59s 10.244.1.4 k8snode2
fluentd-elasticsearch-qxgmc 1/1 Running 0 59s 10.244.0.2 k8smaster
fluentd-elasticsearch-rhhv8 1/1 Running 0 59s 10.244.2.6 k8snode
#通过上面可以看到在 k8s 的三个节点均创建了 fluentd 这个 pod
#pod 的名字是由控制器的名字-随机数组成的

#资源清单详细说明
apiVersion: apps/v1 #DaemonSet 使用的 api 版本
kind: DaemonSet # 资源类型
metadata:
name: fluentd-elasticsearch #资源的名字
namespace: kube-system #资源所在的名称空间
labels:
k8s-app: fluentd-logging #资源具有的标签
spec:
selector: #标签选择器
matchLabels:
name: fluentd-elasticsearch
template:
metadata:
labels: #基于这回模板定义的 pod 具有的标签
name: fluentd-elasticsearch
spec:
tolerations: #定义容忍度

  • key: node-role.kubernetes.io/master
    effect: NoSchedule #只会影响新调度的pod
    containers: #定义容器
  • name: fluentd-elasticsearch
    image: xianchao/fluentd:v2.5.1
    resources: #资源配额
    limits: #最大资源
    memory: 200Mi
    requests: #最小资源
    cpu: 100m
    memory: 200Mi
    volumeMounts:
  • name: varlog
    mountPath: /var/log #把本地/var/log 目录挂载到容器
  • name: varlibdockercontainers
    mountPath: /var/lib/docker/containers #把/var/lib/docker/containers/挂载到容器里
    readOnly: true #挂载目录是只读权限
    terminationGracePeriodSeconds: 30 #优雅的关闭服务
    volumes:
  • name: varlog
    hostPath:
    path: /var/log #基于本地目录创建一个卷 会去采集这个目录下的日志
  • name: varlibdockercontainers
    hostPath:
    path: /var/lib/docker/containers #基于本地目录创建一个卷 同上

### Daemonset 管理 pod:滚动更新



#DaemonSet 实现 pod 的滚动更新
#查看 daemonset 的滚动更新策略
[root@k8smaster ds]# kubectl explain ds.spec.updateStrategy
KIND: DaemonSet
VERSION: apps/v1

RESOURCE: updateStrategy

DESCRIPTION:
An update strategy to replace existing DaemonSet pods with new pods.

 DaemonSetUpdateStrategy is a struct used to control the update strategy for
 a DaemonSet.

FIELDS:
rollingUpdate
Rolling update config params. Present only if type = “RollingUpdate”.

type
Type of daemon set update. Can be “RollingUpdate” or “OnDelete”. Default is
RollingUpdate.

#查看 rollingUpdate 支持的更新策略
[root@k8smaster ds]# kubectl explain ds.spec.updateStrategy.rollingUpdate
KIND: DaemonSet
VERSION: apps/v1

RESOURCE: rollingUpdate

DESCRIPTION:
Rolling update config params. Present only if type = “RollingUpdate”.

 Spec to control the desired behavior of daemon set rolling update.

FIELDS:
maxUnavailable
#上面表示 rollingUpdate 更新策略只支持 maxUnavailabe,先删除在更新;因为我们不支持一个节点运行两个 pod,因此需要先删除一个,在更新一个。

#更新镜像版本,可以按照如下方法:
[root@k8smaster ds]# kubectl set image daemonsets fluentd-elasticsearch fluentd-elasticsearch=nginx -n kube-system
daemonset.apps/fluentd-elasticsearch image updated
#这个镜像启动 pod 会有问题,主要是演示 daemonset 如何在命令行更新 pod 平时不用 都是改yaml
[root@k8smaster ds]# kubectl set image daemonsets fluentd-elasticsearch fluentd-elasticsearch=fluentd -n kube-system
daemonset.apps/fluentd-elasticsearch image updated
#改回来
[root@k8smaster ds]# kubectl get pods -n kube-system

img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以戳这里获取

适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以戳这里获取

  • 10
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值