-
Notifications
You must be signed in to change notification settings - Fork 4
/
kubernetes-example.yml
292 lines (292 loc) · 7.39 KB
/
kubernetes-example.yml
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# https://raw.githubusercontent.com/elastic/beats/7.4/deploy/kubernetes/filebeat-kubernetes.yaml
# with journalbeat and exporter
---
apiVersion: v1
kind: ConfigMap
metadata:
name: beats
namespace: kube-system
labels:
app: beats
data:
beats.yml: |-
max_procs: 1
logging.level: warning # error, warning, info, debug
logging.metrics.enabled: false
# Stats can be access through http://localhost:5066/stats
http:
enabled: true
port: 5066
filebeat.autodiscover:
providers:
- type: kubernetes
host: ${NODE_NAME}
# https://www.elastic.co/guide/en/beats/filebeat/master/configuration-autodiscover-hints.html
hints.enabled: true
hints.default_config:
type: container
paths:
- /var/log/containers/*${data.kubernetes.container.id}.log
# tail_files: 'true' # only for initial sync
multiline:
pattern: '^[[:space:]]+'
match: after
negate: 'false'
max_lines: 500
timeout: 5s
processors:
- drop_fields:
ignore_missing: true
fields:
- kubernetes.labels.pod-template-hash
- kubernetes.labels.pod-template-generation
- kubernetes.labels.controller-revision-hash
- kubernetes.pod.uid
- kubernetes.replicaset.name
- rename:
ignore_missing: true
fields:
- from: kubernetes
to: k8s
- rename:
ignore_missing: true
fields:
- from: k8s.labels
to: ""
- rename:
ignore_missing: true
fields:
- from: stream
to: source
- rename:
ignore_missing: true
fields:
- from: k8s.node.name
to: server
journalbeat:
inputs:
- paths: []
seek: cursor # use 'tail' for first run
processors:
- rename:
ignore_missing: true
fields:
- from: host.hostname
to: server
- rename:
when:
has_fields: ['systemd.unit']
fields:
- from: systemd.unit
to: source
- rename:
when:
not:
has_fields: ['source']
ignore_missing: true
fields:
- from: "syslog.identifier"
to: "source"
- drop_fields:
ignore_missing: true
fields:
- process
- systemd
- journald
- event
- syslog
processors:
- drop_fields:
ignore_missing: true
fields:
- '@metadata'
- agent
- beats
- ecs
- host
- input.type
- log
output.logstash:
hosts:
- "${COLLECTOR}"
max_retries: -1
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: beats
namespace: kube-system
labels:
app: beats
spec:
selector:
matchLabels:
app: beats
template:
metadata:
labels:
app: beats
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8080"
spec:
serviceAccountName: filebeat
enableServiceLinks: false
terminationGracePeriodSeconds: 30
priorityClassName: system-node-critical
containers:
- name: filebeat
image: docker.elastic.co/beats/filebeat:7.4.0
args:
- -c
- /etc/beats/beats.yml
- -e
env:
- name: COLLECTOR
value: logstash.fqdn.local
# needs for k8s discovery
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
securityContext:
runAsUser: 0
resources:
limits:
memory: 100Mi
requests:
cpu: 100m
memory: 100Mi
volumeMounts:
- name: config
mountPath: /etc/beats/
- name: fbdata
mountPath: /usr/share/filebeat/data
- name: varlibdockercontainers
mountPath: /var/lib/docker/containers
readOnly: true
- name: varlog
mountPath: /var/log
readOnly: true
- name: journalbeat
image: docker.elastic.co/beats/journalbeat:7.4.0
args:
- -c
- /etc/beats/beats.yml
- -e
- -E
- http.port=5067
env:
- name: COLLECTOR
value: logstash.fqdn.local
securityContext:
runAsUser: 0
resources:
limits:
memory: 50Mi
requests:
cpu: 100m
memory: 50Mi
volumeMounts:
- name: config
mountPath: /etc/beats/
- name: jbdata
mountPath: /usr/share/journalbeat/data
- name: varlogjournal
mountPath: /var/log/journal
- name: systemd
mountPath: /run/systemd
- name: machine-id
mountPath: /etc/machine-id
readOnly: true
- name: hostname
mountPath: /etc/hostname
readOnly: true
- name: beats-exporter
image: sepa/beats-exporter
imagePullPolicy: Always
args:
- -l=error
- -p=5066
- -p=5067
- -f=version
- -f=uptime
- -f=handles
- -f=output
- -f=pipeline{
securityContext:
runAsUser: 1000
resources:
limits:
memory: 32Mi
requests:
memory: 32Mi
volumes:
- name: config
configMap:
defaultMode: 0600
name: beats
- name: varlogjournal
hostPath:
path: /var/log/journal
- name: machine-id
hostPath:
path: /etc/machine-id
- name: systemd
hostPath:
path: /run/systemd
- name: hostname
hostPath:
path: /etc/hostname
- name: varlibdockercontainers
hostPath:
path: /var/lib/docker/containers
- name: varlog
hostPath:
path: /var/log
# data folder stores a registry of read status for all files, so we don't send everything again on a Beat pod restart
- name: fbdata
hostPath:
path: /var/lib/filebeat-data
type: DirectoryOrCreate
- name: jbdata
hostPath:
path: /var/lib/journalbeat-data
type: DirectoryOrCreate
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: filebeat
subjects:
- kind: ServiceAccount
name: filebeat
namespace: kube-system
roleRef:
kind: ClusterRole
name: filebeat
apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: filebeat
labels:
app: filebeat
rules:
- apiGroups: [""] # "" indicates the core API group
resources:
- namespaces
- pods
verbs:
- get
- watch
- list
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: filebeat
namespace: kube-system
labels:
app: filebeat