• k8s学习-DaemonSet(模板、创建、更新、回滚、删除等)



    概念

    DaemonSet:守护进程集,在kubectl中缩写为ds,在所有节点或者是匹配的节点上都部署一个Pod,当有节点加入集群时, 也会为他们新增一个 Pod 。
    使用DaemonSet的场景

    • 运行集群存储的daemon,比如ceph或者glusterd
    • 节点的CNI网络插件:calico
    • 节点日志的收集:fluentd或者是filebeat
    • 节点的监控:node exporter
    • 服务暴露:部署一个ingress nginx

    日志和监控比较经典。
    我们安装集群的时候,calico和kube-proxy是daemonset的方式启动的。
    在这里插入图片描述

    模板

    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      labels:
        app: nginx
      name: nginx
    spec:
      revisionHistoryLimit: 10
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          creationTimestamp: null
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.15.2
            imagePullPolicy: IfNotPresent
            resources:
              limits:
                memory: 200Mi
              requests:
                cpu: 100m
                memory: 200Mi
          terminationGracePeriodSeconds: 30
    
    • 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

    相较于Deployment,DaemonSet没有副本数,因为他是一个节点启动一个,容器。

    实战

    创建

    命令

     kubectl create -f ds-test.yaml
    
    • 1

    结果
    在这里插入图片描述
    查看全部的yaml
    命令

     kubectl get ds nginx -n killer -o yaml > ds-all.yaml
    
    • 1

    结果

    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      annotations:
        deprecated.daemonset.template.generation: "1"
      creationTimestamp: "2022-06-26T17:16:22Z"
      generation: 1
      labels:
        app: nginx
      name: nginx
      namespace: killer
      resourceVersion: "146918"
      selfLink: /apis/apps/v1/namespaces/killer/daemonsets/nginx
      uid: 50c28ba2-aa39-4fa6-b1c1-97d4b2c7c8f9
    spec:
      revisionHistoryLimit: 10
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          creationTimestamp: null
          labels:
            app: nginx
        spec:
          containers:
          - image: nginx:1.15.2
            imagePullPolicy: IfNotPresent
            name: nginx
            resources:
              limits:
                memory: 200Mi
              requests:
                cpu: 100m
                memory: 200Mi
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
          dnsPolicy: ClusterFirst
          restartPolicy: Always
          schedulerName: default-scheduler
          securityContext: {}
          terminationGracePeriodSeconds: 30
      updateStrategy:
        rollingUpdate:
          maxUnavailable: 1
        type: RollingUpdate
    status:
      currentNumberScheduled: 1
      desiredNumberScheduled: 1
      numberAvailable: 1
      numberMisscheduled: 0
      numberReady: 1
      observedGeneration: 1
      updatedNumberScheduled: 1
    
    
    • 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
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55

    不同于deployment的strategy,ds的回滚策略字段和sts的一样,是updateStrategy。

    更新

    以更新镜像为例
    命令

    kubectl set image  ds nginx nginx=nginx:1.15.3 -n killer --record
    
    • 1

    结果
    在这里插入图片描述

    回滚

    再更新几次之后,查看下更新记录
    命令

    kubectl rollout history ds nginx -n killer
    
    • 1

    结果
    在这里插入图片描述

    回滚到上一版本

    命令

    kubectl rollout undo ds nginx -n killer
    
    • 1

    截图
    在这里插入图片描述

    回滚到指定版本

    命令

    kubectl rollout history ds nginx --revision=2 -n killer
    
    • 1

    截图
    在这里插入图片描述

    删除

    命令

    kubectl delete ds nginx -n killer
    
    • 1

    结果
    在这里插入图片描述

    更多k8s相关内容,请看文章:k8s学习-思维导图与学习笔记

    参考

    k8s-DaemonSet

  • 相关阅读:
    leetcode128 最长连续序列
    论文《Sequential Recommendation with Graph Neural Networks》阅读
    TopoLVM: 基于LVM的Kubernetes本地持久化方案,容量感知,动态创建PV,轻松使用本地磁盘
    发布DDD脚手架到Maven仓库,IntelliJ IDEA 配置一下即可使用
    javacc之路5---词法分析器技巧
    【代码】js闭包
    Spring中的常用注解(一)
    Hadoop简明教程
    Apache Doris 2.1.0 版本发布:开箱盲测性能大幅优化,复杂查询性能提升 100%
    Nmap爆破MySQL弱口令漏洞:解决报错Accounts: No valid accounts found
  • 原文地址:https://blog.csdn.net/lady_killer9/article/details/125469918