当我们把业务跑在了k8s里,日志的收集就不像以往那么简单了,在比较了集中日志收集方案后,我决定采用 volume 共享方式是比较合适的,具体方式就是 app 的日志目录,挂载 volume, 再把此 volume挂载到 filebeat 内,这样就解决了日志来源的问题,就可以发送至es集群,kibana展现,啥都不说了直接上 yaml.
deployment.yaml
-
apiVersion: extensions/v1beta1
-
kind: Deployment
-
metadata:
-
name: app-heartbeat-filebeat
-
namespace: default
-
spec:
-
replicas: 3
-
template:
-
metadata:
-
labels:
-
app: app-heartbeat
-
spec:
-
imagePullSecrets:
-
- name: beijing-vpc-registry
-
containers:
-
- image: registry-vpc.cn-beijing.aliyuncs.com/app/filebeat:0.8
-
name: app-heartbeat-filebeat
-
volumeMounts:
-
- name: logdir
-
mountPath: /logs
-
- name: app-heartbeat-filebeat-config
-
mountPath: /etc/filebeat/filebeat-config/
-
- image: registry-vpc.cn-beijing.aliyuncs.com/app/app-heartbeat:9
-
name : app-heartbeat
-
ports:
-
- containerPort: 8080
-
volumeMounts:
-
- name: logdir
-
mountPath: /data/logs/app-heartbeat/
-
volumes:
-
- name: logdir
-
emptyDir: {}
-
- name: app-heartbeat-filebeat-config
-
configMap:
-
name: app-heartbeat-filebeat-configmap
configmap.yaml
-
apiVersion: v1
-
kind: ConfigMap
-
metadata:
-
name: app-heartbeat-filebeat-configmap
-
data:
-
filebeat.yml: |
-
filebeat.prospectors:
-
- input_type: log
-
paths:
-
- "/logs/app.log"
-
multiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
-
multiline.negate: true
-
multiline.match: after
-
output.elasticsearch:
-
hosts: ["10.6.45.233:9200", "10.6.26.57:9200","10.6.32.176:9200"]
-
template.enabled: false
-
index: "app-heartbeat-%{+yyyy.MM.dd}"
es端上传一些,索引对应的模板,filebeat 就会自动创建索引, 我们登陆 es-head 查看索引是否建立成功。head上索引建立成功,在 es 里建立 相应的Index Pattren即可。
日志展示:
日志条目整合效果
通过设置,我们已经把容器的日志,输入到了es中,完成了任务。
阅读(5407) | 评论(0) | 转发(0) |