簡介
通過sidecar方法進行接入,與提供日志的容器部署在同一個pod裡,主要是配置statefulset裡的containers和configmap裡的filebeat.yaml
1.把nginx的日志檔案挂載在access_log這個volume裡,同時在filebeat這個pod裡也挂載access_log這個volume
2.filebeat通過subpath的方法挂載單獨一個filebeat.yml到/usr/share/filebeat/filebeat.yml。注意,如果不用subpath挂載單個檔案的話,是會覆寫掉/usr/share/filebeat/目錄的
3.configmap裡設定elasticsearch的位址和index,指定日志檔案
statefulset.yaml
containers:
- image: nginx:latest
name: nginx
ports:
- containerPort: 80
volumeMounts:
- name: access-log #日志同時挂載在nginx和filebeat中
mountPath: /var/log/nginx/
- image: docker.elastic.co/beats/filebeat:6.8.12
imagePullPolicy: Always
name: filebeat
volumeMounts:
- name: access-log #日志同時挂載在nginx和filebeat中
mountPath: /log
- name: filebeat-config
mountPath: /usr/share/filebeat/filebeat.yml
subPath: filebeat.yml
volumes:
- name: filebeat-config
configMap:
name: filebeat-config
items:
- key: filebeat.yml
path: filebeat.yml
configmap.yaml
---
apiVersion: v1
kind: ConfigMap
metadata:
name: filebeat-config
data:
filebeat.yml: |
filebeat.inputs:
- type: log
paths:
- "/log/access.log"
setup.template.name: "filebeat"
setup.template.pattern: "filebeat-*"
output.elasticsearch:
hosts: ["{{ .Values.elastricsearch.addr }}"]
index: "frontend-filebeat"