k8s部署filebeat收集日志推送kafka

本文介绍如何在Kubernetes环境中使用Filebeat收集日志并发送到Kafka。具体步骤包括拉取Filebeat镜像、配置Filebeat参数、编写Deployment文件等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        网上有许多方案,今天我们采用在pod中部署专有日志收集容器的方式来实现,话不多说,下面干货。

1、官网pull镜像

docker pull docker.elastic.co/beats/filebeat:8.4.3

        文档地址:https://www.elastic.co/guide/en/beats/filebeat/current/running-on-docker.html

2、编写filebeat.yml

filebeat.inputs:
- type: log
  paths:
    - /logs/*.log
output.kafka:
  # 录入kafka地址
  hosts: ["xxx.xxx.xxx.xxx:9092"]

  # 录入自己的topic
  topic: '%{[fields.log_topic]}'
  partition.round_robin:
    reachable_only: false

  required_acks: 1
  compression: gzip
  max_message_bytes: 1000000

         文档:

                https://www.elastic.co/guide/en/beats/filebeat/8.4/filebeat-input-log.html

        ​​​​​​​        https://www.elastic.co/guide/en/beats/filebeat/8.4/kafka-output.html

3、编写deployment.yaml

        "......"表示省略,只展示关键代码

……
spec:
  volumes:
    - name: filebeat
      configMap: filebeat
        - key: filebeat.yml
          path: filebeat.yml
        defaultMode: 420
    - name: nginx-log
      emptyDir: {}
  containers:
    - name: nginx
      image: nginx
……
      volumMounts:
        - name: nginx-log
          mountPath: /var/log/nginx
    - name: filebeat
      image: docker.elastic.co/beats/filebeat:8.4.3
      args:
        - '-c'
        - '/etc/filebeat.yml'
        - '-e'
        - '--strict.perms=false'
      volumeMounts:
        - name: filebeat
          readOnly: true
          mountPath: /etc/filebeat.yml
          subPath: filebeat.yml
        - name: nginx-log
          readOnly: true
          mountPaht: /logs
……

4、在kafka验证是否有记录

./kafka-console-consumer.sh --bootstrap-server xxx.xxx.xxx.xxx:9092 --topic xxx --from-beginning

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值