zoukankan      html  css  js  c++  java
  • DaemonSet

    1.概念阐述

    DaemonSet:守护进程集,缩写为ds,在所有节点或者是匹配的节点上都部署一个Pod。
    DaemonSet确保全部(或者某些)节点上运行一个Pod副本。当有新节点加入集群时,也会为它们新增一个Pod。当节点从集群中移除时,这些Pod也会被回收,删除DaemonSet将会删除它创建的所有Pod
      使用DaemonSet的一些典型用法:
    	 运行集群存储daemon(守护进程),例如在每个节点上运行Glusterd、Ceph等
    	 在每个节点运行日志收集daemon,例如Fluentd、Logstash
    	 在每个节点运行监控daemon,比如Prometheus Node Exporter、Collectd、Datadog代理、New Relic代理或 Ganglia gmond
    

    2.创建一个DaemonSet

    [root@k8s-master01 ~]# cat > nginx-ds.yaml  << EFO
    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:
          - image: nginx:1.15.2
            imagePullPolicy: IfNotPresent
            name: nginx
            resources: {}
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
          dnsPolicy: ClusterFirst
          restartPolicy: Alwaysyaml
          schedulerName: default-scheduler
          securityContext: {}
          terminationGracePeriodSeconds: 30
    EFO
    

    3.创建一个ds

    # 创建一个ds
    [root@k8s-master01 ~]# kubectl create -f nginx-ds.yaml 
    daemonset.apps/nginx created
    
    # 查看ds信息,个个节点都有一个
    [root@k8s-master01 ~]# kubectl get node -owide
    NAME           STATUS   ROLES    AGE   VERSION   INTERNAL-IP     EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION                CONTAINER-RUNTIME
    k8s-master01   Ready    matser   43h   v1.20.0   192.168.1.100   <none>        CentOS Linux 7 (Core)   4.19.12-1.el7.elrepo.x86_64   docker://19.3.14
    k8s-master02   Ready    <none>   43h   v1.20.0   192.168.1.101   <none>        CentOS Linux 7 (Core)   4.19.12-1.el7.elrepo.x86_64   docker://19.3.14
    k8s-master03   Ready    <none>   43h   v1.20.0   192.168.1.102   <none>        CentOS Linux 7 (Core)   4.19.12-1.el7.elrepo.x86_64   docker://19.3.14
    k8s-node01     Ready    <none>   43h   v1.20.0   192.168.1.103   <none>        CentOS Linux 7 (Core)   4.19.12-1.el7.elrepo.x86_64   docker://19.3.14
    k8s-node2      Ready    <none>   43h   v1.20.0   192.168.1.104   <none>        CentOS Linux 7 (Core)   4.19.12-1.el7.elrepo.x86_64   docker://19.3.14
    

    4.给node节点打lable

    [root@k8s-master01 ~]# kubectl label node k8s-node01 k8s-node02 ds=true
    [root@k8s-master01 ~]# kubectl get node --show-labels  ### 查看标签
    

    5.更新

    [root@k8s-master01 ~]# cat -n nginx-ds.yaml 
         1	apiVersion: apps/v1
         2	kind: DaemonSet
         3	metadata:
         4	  labels:
         5	    app: nginx
         6	  name: nginx
         7	spec:
         8	  revisionHistoryLimit: 10
         9	  selector:
        10	    matchLabels:
        11	      app: nginx
        12	  template:
        13	    metadata:
        14	      creationTimestamp: null
        15	      labels:
        16	        app: nginx
        17	    spec:
        18	      nodeSelector: # 新增
        19	        ds: "ture"  # 定义我们打label的节点上起DS pod
        20	      containers:
        21	      - image: nginx:1.15.2
        22	        imagePullPolicy: IfNotPresent
        23	        name: nginx
        24	        resources: {}
        25	        terminationMessagePath: /dev/termination-log
        26	        terminationMessagePolicy: File
        27	      dnsPolicy: ClusterFirst
        28	      restartPolicy: Always
        29	      schedulerName: default-scheduler
        30	      securityContext: {}
        31	      terminationGracePeriodSeconds: 30
    [root@k8s-master01 ~]# kubectl replace -f nginx-ds.yaml 
    

    6.验证查看

    [root@k8s-master01 ~]# kubectl get pod -owide
    NAME                     READY   STATUS    RESTARTS   AGE     IP               NODE         NOMINATED NODE   READINESS GATES
    nginx-cpbpb              1/1     Running   0          7m51s   172.16.85.242    k8s-node01   <none>           <none>
    nginx-hmwxf              1/1     Running   0          7m37s   172.16.169.137   k8s-node2    <none>           <none>
    
  • 相关阅读:
    java多线程设计模式
    Java横向、纵向合并图片
    Oracle数据库当前连接数、最大连接数的查询与设置
    oracle获取一段时间内所有的小时、天、月
    Struts2+Spring3+Mybatis3开发环境搭建
    Spring3.3 整合 Hibernate3、MyBatis3.2 配置多数据源/动态切换数据源方法
    spring+mybatis 多数据源切换
    Java与WCF交互(一):Java客户端调用WCF服务
    使用axis2进行WebService的开发
    axis2 WebService的发布与调用
  • 原文地址:https://www.cnblogs.com/Applogize/p/14398354.html
Copyright © 2011-2022 走看看