Filebeat 使用 Node 方式收集k8s集群日志
# Filebeat 使用 Node 方式收集k8s集群日志
# 思路简述
容器的日志在每台Node的 /var/log/containers 目录
我们可以使用DaemonSet的方式, 在每台机器上都部署一个Filebeat容器, 统一收集这些日志.
既不侵入项目, 占用资源还少.
# 镜像准备
see bringg/filebeat-kubernetes
# DaemonSet配置
filebeat-daemonset.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: pods-logger
spec:
selector:
matchLabels:
name: pods-logger
template:
metadata:
labels:
name: pods-logger
spec:
containers:
- name: filebeat
image: bringg/filebeat-kubernetes
imagePullPolicy: Always
env:
- name: LOGSTASH_HOSTS
value: elk-logstash-service:5044
- name: LOG_LEVEL
value: info
- name: FILEBEAT_HOST
valueFrom:
fieldRef:
fieldPath: spec.nodeName
resources:
limits:
cpu: 100m
memory: 256Mi
volumeMounts:
- name: var-log-containers
mountPath: /var/log/containers
- name: var-log-pods
mountPath: /var/log/pods
readOnly: true
- name: var-lib-docker-containers
mountPath: /var/lib/docker/containers
readOnly: true
volumes:
- name: var-log-containers
hostPath: { path: /var/log/containers }
- name: var-log-pods
hostPath: { path: /var/log/pods }
- name: var-lib-docker-containers
hostPath: { path: /var/lib/docker/containers }
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 参考文档
上次更新: 2020/06/11, 18:06:00