2. DaemonSet
DaemonSet 确保全部(或者某些)节点上运行一个 Pod 的副本。 当有节点加入集群时, 也会为他们新增一个 Pod 。 当有节点从集群移除时,这些 Pod 也会被回收。删除 DaemonSet 将会删除它创建的所有 Pod。
DaemonSet 的一些典型用法:
- 在每个节点上运行集群守护进程
- 在每个节点上运行日志收集守护进程
- 在每个节点上运行监控守护进程
一种简单的用法是为每种类型的守护进程在所有的节点上都启动一个 DaemonSet。 一个稍微复杂的用法是为同一种守护进程部署多个 DaemonSet;每个具有不同的标志, 并且对不同硬件类型具有不同的内存、CPU 要求。
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd-elasticsearch
namespace: kube-system
labels:
k8s-app: fluentd-logging
spec:
selector:
matchLabels:
name: fluentd-elasticsearch
template:
metadata:
labels:
name: fluentd-elasticsearch
spec:
tolerations:
# 这些容忍度设置是为了让该守护进程集在控制平面节点上运行
# 如果你不希望自己的控制平面节点运行 Pod,可以删除它们
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
- key: node-role.kubernetes.io/master
operator: Exists
effect: NoSchedule
containers:
- name: fluentd-elasticsearch
image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: varlog
mountPath: /var/log
- name: varlibdockercontainers
mountPath: /var/lib/docker/containers
readOnly: true
terminationGracePeriodSeconds: 30
volumes:
- name: varlog
hostPath:
path: /var/log
- name: varlibdockercontainers
hostPath:
path: /var/lib/docker/containers
在每个节点都启动了fluentd-elasticsearch的pod
root@k8s-master-01:~/yml# kubectl get pods -o wide -n kube-system
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
calico-kube-controllers-76586bcfb6-2pmfx 1/1 Running 1 100d 192.168.31.111 192.168.31.111 <none> <none>
calico-node-48nd2 1/1 Running 0 52d 192.168.31.102 192.168.31.102 <none> <none>
calico-node-6csj7 1/1 Running 0 52d 192.168.31.103 192.168.31.103 <none> <none>
calico-node-brphr 1/1 Running 1 100d 192.168.31.112 192.168.31.112 <none> <none>
calico-node-jd8xr 1/1 Running 0 52d 192.168.31.101 192.168.31.101 <none> <none>
calico-node-pl8sz 1/1 Running 0 3d7h 192.168.31.113 192.168.31.113 <none> <none>
calico-node-xzfgw 1/1 Running 1 100d 192.168.31.111 192.168.31.111 <none> <none>
coredns-55556fc4d7-5qnzw 1/1 Running 0 3d7h 172.100.109.70 192.168.31.111 <none> <none>
fluentd-elasticsearch-75dsf 1/1 Running 0 37s 172.100.140.76 192.168.31.112 <none> <none>
fluentd-elasticsearch-g298m 1/1 Running 0 37s 172.100.95.1 192.168.31.102 <none> <none>
fluentd-elasticsearch-ndttm 1/1 Running 0 37s 172.100.151.129 192.168.31.101 <none> <none>
fluentd-elasticsearch-nl67m 1/1 Running 0 37s 172.100.109.72 192.168.31.111 <none> <none>
fluentd-elasticsearch-pztpt 1/1 Running 0 37s 172.100.76.141 192.168.31.113 <none> <none>
fluentd-elasticsearch-wgvvg 1/1 Running 0 37s 172.100.183.129 192.168.31.103 <none> <none>
metrics-server-994ccf56d-wqhq6 1/1 Running 0 3d7h 172.100.140.71 192.168.31.112 <none> <none>