k8s给出一个使用sidecar的案例用filebeat收集nginx的日志给出deployment yaml文件
下面是一个使用sidecar模式来收集Nginx日志的示例Deployment YAML文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-filebeat
labels:
app: nginx-filebeat
spec:
replicas: 1
selector:
matchLabels:
app: nginx-filebeat
template:
metadata:
labels:
app: nginx-filebeat
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
- name: filebeat
image: docker.elastic.co/beats/filebeat:7.15.1
volumeMounts:
- name: nginx-logs
mountPath: /var/log/nginx
readOnly: true
- name: filebeat-config
mountPath: /usr/share/filebeat/filebeat.yml
subPath: filebeat.yml
volumes:
- name: nginx-logs
emptyDir: {}
- name: filebeat-config
configMap:
name: filebeat-configmap
---
apiVersion: v1
kind: ConfigMap
metadata:
name: filebeat-configmap
data:
filebeat.yml: |
filebeat.inputs:
- type: log
paths:
- /var/log/nginx/*.log
output.elasticsearch:
hosts: ["your-elasticsearch-host:9200"]
解释:
metadata部分定义了Deployment的名称和标签。replicas指定了副本数量为1。selector部分定义了选择器以选择要管理的Pod。template部分定义了Pod的模板。containers部分包含了两个容器:nginx和filebeat。nginx容器使用nginx:latest镜像,并监听80端口。filebeat容器使用docker.elastic.co/beats/filebeat:7.15.1镜像,并挂载了两个卷。nginx-logs卷用于将Nginx日志文件挂载到容器的/var/log/nginx目录下。filebeat-config卷用于将Filebeat的配置文件filebeat.yml挂载到容器的/usr/share/filebeat/filebeat.yml路径下。
volumes部分定义了两个卷:nginx-logs卷是一个空目录卷,用于存储Nginx的日志文件。filebeat-config卷是一个ConfigMap卷,将Filebeat的配置文件filebeat.yml通过ConfigMap方式提供。
ConfigMap部分定义了Filebeat的配置文件filebeat.yml,其中指定了要收集的日志路径和输出到的Elasticsearch地址。
请根据实际情况修改filebeat.yml中的Elasticsearch地址和其他配置。
原文地址: https://www.cveoy.top/t/topic/i7dj 著作权归作者所有。请勿转载和采集!