Kuberbetes的DaemonSet
DaemonSet确保全部(或者一些)Node上运行一个Pod的副本。当有Node加入集群时,也会为他们新增一个Pod,当有Node从集群移除时,这些Pod也会被回收,删除DaemonSet将会删除他创建的所有Pod
使用daemonSet的一些典型用法:
- 运行集群存储Daemon,例如在每个Node上运行glusterd、ceph
- 在每个Node上运行日志收集daemon,例如fluentd、logstash
- 在每个Node上运行监控daemon,例如Prometheus Node Exporter、collectd、datadog代理、new relic代理或者Ganglia gmond
apiVersion: apps/v1 kind: DaemonSet metadata: name: ds-test labels: app: filebeat spec: selector: matchLabels: app: filebeat template: metadata: labels: app: filebeat spec: containers: - name: logs image: nginx ports: - containerPort: 80 volumeMounts: - name: varlog mountPath: /tmp/log volumes: - name: varlog hostPath: path: /var/log
执行并查看日志
[root@test yaml]# kubectl apply -f ds.yaml daemonset.apps/ds-test created [root@test yaml]# kubectl get pods NAME READY STATUS RESTARTS AGE ds-test-gs6z5 1/1 Running 0 10s ds-test-xfjgt 1/1 Running 0 10s web-586db47859-6vpfr 1/1 Running 0 23h web-586db47859-8hmxs 1/1 Running 0 23h web-586db47859-wspl7 1/1 Running 0 23h [root@test yaml]# kubectl exec -it ds-test-gs6z5 bash kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead. root@ds-test-gs6z5:/# ls bin boot dev docker-entrypoint.d docker-entrypoint.sh etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var root@ds-test-gs6z5:/# ls tmp/log/ audit btmp-20201201 cron-20201206 kube-apiserver maillog-20201206 ntpstats secure-20201115 spooler-20201129 zabbix boot.log chrony dmesg kubernetes messages pods secure-20201122 spooler-20201206 boot.log-20200821 containers dmesg.old lastlog messages-20201115 qemu-ga secure-20201129 tallylog boot.log-20200825 cron elasticsearch maillog messages-20201122 redis secure-20201206 tuned boot.log-20200915 cron-20201115 firewalld maillog-20201115 messages-20201129 rhsm spooler wtmp boot.log-20201107 cron-20201122 grubby maillog-20201122 messages-20201206 sa spooler-20201115 yum.log btmp cron-20201129 grubby_prune_debug maillog-20201129 mongodb secure spooler-20201122 yum.log-20201120 root@ds-test-gs6z5:/# exit exit