DaemonSet

DaemonSet

DaemonSet用于在每个Kubernetes节点中将守护进程的副本作为后台运行,当节点从集群中被移除后,该节点上的Pod也会被移除,当然,如果我们删除DaemonSet,所有和这个对象相关的Pods都会被删除。

适用场景

  • 集群存储守护程序,如glusterd、ceph要部署在每个节点上提供持久性存储
  • 节点监视守护进程,如prometheus监控集群,可以在每个节点上运行一个node-exporter进程来收集监控节点的信息
  • 日志收集守护程序,如fluentd或logstash,在每个节点运行容器

DaemonSet Pods调度特性

默认情况下,Pod被分配到具体哪一台Node节点运行是由Scheduler (它通过监听ApiServer,查询还未分配的Node的Pod,根据调度策略为这些Pod进行调度)。但是DaemonSet对象创建的Pod却拥有一些特殊的特性

  • Node的unchedulable属性会被DaemonSet Controller忽略
  • 即使Scheduler还未启动,DaemonSet Controller也能够创建并运行Pod

下面我们创建一个nginx配置文件进行演示

cat >daemonset-nginx.yaml<<EOF
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: nginx-ds
  labels:
    app: nginx
spec:
  template:
    metadata:
      labels:
        k8s-app: nginx
    spec:
        containers:
        - name: nginx
          image: nginx
          ports:
          - name: http
            containerPort: 80
EOF

因为上面说了,daemonSet是根据我们节点的数量进行创建,同时我们没有在master添加taints。所以在master也会创建一个容器

[root@abcdocker yaml]# kubectl get pod -o wide
NAME             READY   STATUS    RESTARTS   AGE     IP             NODE           NOMINATED NODE   READINESS GATES
nginx-ds-dfs6t   1/1     Running   0          9m27s   172.30.144.6   k8s-master03   <none>           <none>
nginx-ds-hkvmr   1/1     Running   0          9m26s   172.30.112.5   k8s-node       <none>           <none>
nginx-ds-kkscb   1/1     Running   0          9m27s   172.30.80.11   k8s-master02   <none>           <none>
nginx-ds-lvnnb   1/1     Running   0          9m28s   172.30.24.8    k8s-master01   <none>           <none>
[root@abcdocker yaml]# kubectl get node
NAME           STATUS   ROLES    AGE    VERSION
k8s-master01   Ready    <none>   100d   v1.14.2
k8s-master02   Ready    <none>   100d   v1.14.2
k8s-master03   Ready    <none>   100d   v1.14.2
k8s-node       Ready    <none>   100d   v1.14.2

[root@abcdocker yaml]# kubectl get daemonset
NAME       DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
nginx-ds   4         4         4       4            4           <none>          23m
Copyright © i4t.com 2019 all right reserved,powered by Gitbook该文件修订时间: 2019-12-06 17:02:47

results matching ""

    No results matching ""