• 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
  • 相关阅读:
    机器学习与模式识别作业----决策树属性划分计算
    pg_dump备份多张表到不同的sql文件
    新零售mysql设计(采购表 入库信息表 入库商品表)
    【k8s学习2】二进制文件方式安装 Kubernetes之etcd集群部署
    MinIO - 站点复制 Site Replication
    JMeter参数化4种实现方式
    电脑怎么录音,亲身测评,让你事半功倍!
    AI数字人SadTalker实战
    利用TreeMap来解决P3029 [USACO11NOV] Cow Lineup S
    08数组-滑动窗口、HashMap
  • 原文地址:https://blog.csdn.net/yy8623977/article/details/124877484