---
apiVersion: v1
kind: ConfigMap
metadata:
name: filebeat-config
namespace: default
labels:
app: filebeat
data:
filebeat.yml: |-
filebeat.inputs:
- type: filestream
enabled: true
paths:
- /opt/log/access.log #收集日志文件的绝对路径
output.elasticsearch:
hosts: ["http://192.168.10.3:9200"] #es的ip:端口
index: "web_log" #索引名称
setup.ilm.enabled: false #禁用索引生命周期管理
setup.template.name: "gx-test" #设置索引模板的名称
setup.template.pattern: "gx-test*" #设置索引模板的匹配模式,eg:gx-test1,gx-test2
setup.template.overwrite: true #覆盖已有的索引模板,如果为true,则会直接覆盖现有的索引模板,如果为false则不覆盖!
---
apiVersion: v1
kind: Service
metadata:
name: kibana
namespace: default
labels:
app: kibana
spec:
ports:
- port: 5601
type: NodePort
selector:
app: kibana
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: kibana
namespace: default
labels:
app: kibana
spec:
selector:
matchLabels:
app: kibana
template:
metadata:
labels:
app: kibana
spec:
containers:
- name: kibana
image: kubeimages/kibana:7.10.2
env:
- name: ELASTICSEARCH_HOSTS
value: http://172.16.0.19:9200
ports:
- containerPort: 5601
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: web
name: web
spec:
replicas: 1
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
volumeMounts:
- name: log
mountPath: /var/log/nginx/
- name: filebeat
image: kubeimages/filebeat:7.10.2
imagePullPolicy: IfNotPresent
args: [
"-c", "/etc/filebeat.yml",
"-e",
]
volumeMounts:
- name: config
mountPath: /etc/filebeat.yml
readOnly: true
subPath: filebeat.yml
- name: log
mountPath: /opt/log/ #与nginx的 mountpath 是同一存储,若需要收集nginx的access.log日志,则filebeat的配置文件中paths为/opt/log/access.log
volumes:
- name: log #pod的共享存储
emptyDir: {}
- name: config
configMap:
defaultMode: 0640
name: filebeat-config #filebeat的配置文件