首页 > 其他分享 >k8s部署elk+filebeat+kafka-kraft模式集群(三)filebeat部署

k8s部署elk+filebeat+kafka-kraft模式集群(三)filebeat部署

时间:2022-09-29 15:24:29浏览次数:54  
标签:elk filebeat name 部署 kafka k8s metadata

k8s集群部署filebeat
filebeat需要采集每个节点的容器日志,所以我们选择daemonset的方式

# cat filebeat-rbac.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: filebeat
  namespace: elk
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: filebeat
  labels:
    app: filebeat-clsterrole
rules:
- apiGroups:
  - ""
  resources:
  - nodes
  - events
  - namespaces
  - pods
  verbs:
  - get
  - watch
  - list
- apiGroups:
  - ""
  resourceNames:
  - filebeat-prospectors
  resources:
  - configmaps
  verbs:
  - get
  - update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: filebeat
  labels:
    app: filebeat-clusterrolebinding
roleRef:
  apiGroup: ""
  kind: ClusterRole
  name: filebeat
subjects:
- apiGroup: ""
  kind: ServiceAccount
  name: filebeat
  namespace: elk
# cat filebeat-cm.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: filebeat-configmap
  namespace: elk
data:
  filebeat.yml: |-
    filebeat.autodiscover:
      providers:
        - type: kubernetes
          node: ${NODE_NAME}
          hints.enabled: true
          hints.default_config:
            type: container
            paths:
              - /var/log/containers/*${data.kubernetes.container.id}.log
            tags: ["k8s"]
            fields:
              log_topic: k8s
    filebeat.config.modules:
      path: ${path.config}/modules.d/*.yml
    setup.template.settings:
      index.number_of_shards: 3
      index.number_of_replicas: 1
      index.codec: best_compression
      _source.enabled: false
    output.kafka:
      hosts: ["kafka-kraft-statefulset-0.kafka-kraft-svc:9091","kafka-kraft-statefulset-1.kafka-kraft-svc:9091","kafka-kraft-statefulset-2.kafka-kraft-svc:9091"]
      topic: '%{[fields.log_topic]}'
      partition.round_robin:
        reachable_only: false
      required_acks: 1
      compression: gzip
      max_message_bytes: 1000000
		processors:
      - add_host_metadata:
          when.not.contains.tags: forwarded
      - add_cloud_metadata: ~
      - add_docker_metadata: ~
      - add_kubernetes_metadata: ~
# cat filebeat.yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: filebeat
  namespace: elk
  labels:
    k8s-app: filebeat
spec:
  selector:
    matchLabels:
      k8s-app: filebeat
  template:
    metadata:
      labels:
        k8s-app: filebeat
    spec:
      serviceAccountName: filebeat
      terminationGracePeriodSeconds: 30
      containers:
      - name: filebeat
        image: 3.127.33.174:8443/elk/filebeat:8.1.0
        imagePullPolicy: IfNotPresent
        command: [
          "filebeat",
          "-e",
          "-c", "/etc/filebeat.yml"
        ]
        env:
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
				securityContext:
          runAsUser: 0
        resources:
          limits:
            memory: 1000Mi
            cpu: 1000m
          requests:
            memory: 100Mi
            cpu: 100m
        volumeMounts:
        - name: config
          mountPath: /etc/filebeat.yml
          readOnly: true
          subPath: filebeat.yml
        - name: data
          mountPath: /usr/share/filebeat/data
        - name: dockerlog
          mountPath: /home/docker/docker/containers
        - name: varlog
          mountPath: /var/log/
          readOnly: true
        - name: timezone
          mountPath: /etc/localtime
      volumes:
      - name: config
        configMap:
          defaultMode: 0644
          name: filebeat-configmap
      - name: dockerlog
        hostPath:
          path: /home/docker/docker/containers/
      - name: varlog
        hostPath:
          path: /var/log/
      - name: data
				hostPath:
          path: /home/k8s/data
          type: DirectoryOrCreate
      - name: timezone
        hostPath:
          path: /etc/localtime
      tolerations:
      - effect: NoExecute
        key: dedicated
        operator: Equal
        value: gpu
      - effect: NoSchedule
        operator: Exists

[root@k8s-master01 filebeat]# kubectl get pods -n elk -o wide | grep filebeat
img
filebeat部署完毕,可以进入kafka中查看是否正常往topic中推送数据
img
也可以通过挂载容器日志的方式去采集每个容器的日志

apiVersion: v1
kind: ConfigMap
metadata:
  name: filebeat-configmap
  namespace: elk
data:
  filebeat.yml: |-
    filebeat.inputs:
    - type: log
      paths:
        - /var/log/pods/*.log
      fields:
        node: ${HOSTNAME}
      fields_under_root: true
      # 此参数非常重要,filebeat默认会忽略软链接
      symlinks: true
      tags: ["k8s"]

标签:elk,filebeat,name,部署,kafka,k8s,metadata
From: https://www.cnblogs.com/precomp/p/16741671.html

相关文章

  • 二进制部署k8s集群v1.23.9版本-21-安装LTS任务调度
    21.1、准备镜像192.168.1.200服务器操作lts-jobtracker镜像dockerpullharbor.qgutech.com/qx-apaas/lts-jobtracker:v1dockertag8f1e3d395515harbor.qgutech.com/......
  • k8s部署elk+filebeat+kafka-kraft模式集群(二)kafka-zk集群
    kafka-zookeeper集群部署zk使用官方镜像,版本为3.5本文跳过rbac之类配置,与前文相同#catzk-statefulset.yamlapiVersion:v1kind:Servicemetadata:name:zk-svc......
  • k8s部署elk+filebeat+kafka-kraft模式集群(一)ES集群+kibana部署
    前言:这次是在部署后很久才想起来整理了下文档,如有遗漏见谅,期间也遇到过很多坑有些目前还没头绪希望有大佬让我学习下一、环境准备k8s-master013.127.10.209k8s-ma......
  • minio通过docker方式部署
    MinIO是在GNUAffero通用公共许可证v3.0下发布的高性能对象存储。它是与AmazonS3云存储服务兼容的API官方文档http://docs.minio.org.cn/docs/master/minio-adm......
  • Docker部署SQL Server 2019 Always On集群
    Docker部署Alwayson集群SQLServer在2016年开始支持Linux。随着2017和2019版本的发布,它开始支持Linux和容器平台上的HA/DR、Kubernetes和大数据集群解决方案。在本文中,我们......
  • Docker基础知识 (13) - 部署 MariaDB 集群 (一) | 主从复制
    MariaDB数据库是MySQL的一个分支,主要由开源社区维护,采用GPL授权许可MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。在存储引擎方......
  • 项目优化打包部署
    一、项目优化1.去掉打印console需求:在开发环境中,保留打印console;在生产上线环境,自动去掉打印console使用步骤:第一步:在项目根目录下,创建如下图两个配置文件在.......
  • openshift3.11社区版部署
    安装注意事项 1、保证能联网2、开启Selinux3、操作系统语言不能是中文4、infra节点会自动部署router,lb不要放在infra节点上,所以80端口不能冲突5、如果webconsole访......
  • ssdb单机部署
    环境:OS:Centos7db:1.9.81.下载安装介质[root@localhostsoft]#wget--no-check-certificatehttps://github.com/ideawu/ssdb/archive/master.zip2.解压安装[root@loc......
  • Oracle部署,关于日志文件系统选择(硬盘格式化、挂载)
    之前部署过好多Oracle服务,采用的日志文件系统一直是ext3。但是我观察到很多人在格式化/挂载数据盘时,采用的日志文件系统类型有ext3、ext4、xfs等,这不禁让我发出疑问,哪个类......