• Kubernetes(k8s)的Pod控制器DaemonSet详细讲解


    1. 概述

    DaemonSet类型的控制器可以保证集群中的每一台(或指定)节点上都运行一个且只有一个副本,一般适用于日志收集、节点监控等场景

    DaemonSet控制器的特点:

    • 每向集群中添加一个节点的时候,指定的Pod副本也将添加到该节点上
    • 当节点从集群中移除的时候,Pod也会被垃圾回收

    DaemonSet

    DaemonSet的资源清单模板

    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      name: pod-controller                      # ds名称
      namespace: dev                            # ds所属的命名空间
      labels:                                   # 给ds打标签
        controller: daemonset
    spec:
      revisionHistoryLimit: 3                   # 保留历史版本数量,默认为10
      updateStrategy:                           # Pod更新策略,默认是RollingUpdate
        type: RollingUpdate                     # 滚动更新策略。另一种是OnDelete,其没有子属性配置参数 
        rollingUpdate:                          # 当type为RollingUpdate的时候生效,为其配置参数
          maxSurge: 25%                         # 升级过程中可以超过期望的Pod的最大数量,可以为百分比,也可以为整数。默认是25%
          maxUnavailable: 25%                   # 升级过程中最大不可用状态的Pod数量,可以为百分比,也可以为整数。默认是25%
      selector:                                 # 选择器,通过该控制器管理哪些pod
        matchLabels:                            # Labels匹配规则。和matchExpressions类似
          app: nginx-pod
        matchExpressions:                     # Expressions匹配规则。和matchLabels类似 
          - {key: app, operator: In, values: ["nginx-pod"]} 
      template:                                 # pod副本创建模板。属性和Pod的属性一样
         metadata:
           labels:
             app: nginx-pod
         spec:
           containers:
             - name: nginx
               image: nginx:latest
               ports:
                 - name: nginx-port
                   containerPort: 80
                   protocol: TCP
    
    • 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

    2. DaemonSet的创建、查看、删除

    2.1 DaemonSet的创建

    新建pod-controller.yaml,内容如下。并运行DaemonSet

    [root@k8s-master ~]# cat pod-controller.yaml
    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      name: pod-controller
      namespace: dev
      labels:
        controller: daemonset
    spec:
      selector:
        matchLabels:
          app: nginx-pod
      template:
         metadata:
           labels:
             app: nginx-pod
         spec:
           containers:
             - name: nginx
               image: nginx:latest
               ports:
                 - name: nginx-port
                   containerPort: 80
                   protocol: TCP
    [root@k8s-master ~]# 
    [root@k8s-master ~]# kubectl apply -f pod-controller.yaml 
    daemonset.apps/pod-controller created
    [root@k8s-master ~]# 
    
    • 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

    2.2 DaemonSet的查看

    [root@k8s-master ~]# kubectl get ds -n dev -o wide
    NAME             DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE   CONTAINERS   IMAGES         SELECTOR
    pod-controller   2         2         2       2            2                     61s   nginx        nginx:latest   app=nginx-pod
    [root@k8s-master ~]#
    
    • 1
    • 2
    • 3
    • 4

    2.3 DaemonSet的删除

    [root@k8s-master ~]# kubectl delete ds pod-controller -n dev
    daemonset.apps "pod-controller" deleted
    [root@k8s-master ~]# 
    
    • 1
    • 2
    • 3
  • 相关阅读:
    多目标蜉蝣优化算法(MOMA)附Matlab代码
    aws s3上传文件
    CS109: Probability for Computer Scientists, Summer 2022笔记合集
    1.3.19 网络端口地址转换 NAPT 配置
    相机投影矩阵计算
    查询效率提升10倍!3种优化方案,帮你解决MySQL深分页问题
    Java 把多个音频拼接成一个
    DC-DC电源模块 直流升压低压升高压变换器 小体积
    JK405R-SOP16录音芯片ic方案的测试板使用说明以及咪头如何选择
    android 内存管理
  • 原文地址:https://blog.csdn.net/yy8623977/article/details/124877484