当前位置: 首页 > news >正文

Kubernetes集群通过Filebeat收集日志

Filebeat收集容器日志,其中NODE_NAME配置,是将node信息添加到日志中,所以需要serviceAccount权限,如果不需要配置NODE信息,可以不创建serviceAccount,其他内容可根据实际情况修改

apiVersion: v1
kind: ServiceAccount
metadata:
  name: filebeat
  namespace: elk
  labels:
    app: filebeat
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: filebeat-clusterrole
  labels:
    app: filebeat
rules:
- apiGroups: [""]
  resources:
  - nodes
  - namespaces
  - pods
  verbs:
  - watch
  - get
  - list
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: filebaet-clusterrolebinding
  labels:
    app: filebeat
subjects:
- kind: ServiceAccount
  name: filebeat
  namespace: elk
roleRef:
  kind: ClusterRole
  name: filebeat-clusterrole
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: filebeat
  namespace: elk 
data:
  filebeat.yml: |-
    filebeat.inputs:
    - type: container 
      paths:
      - /var/log/containers/*.log
      processors:
        - add_kubernetes_metadata:
            in_cluster: true
            host: ${NODE_NAME}
        - add_fields:
            fields:
              node_name: ${NODE_NAME}

    output.elasticsearch:
      hosts: ["http://elasticsearch:9200"]
      indices:
        - index: "containers_log"
    setup.template.name: "containers"
    setup.template.pattern: "containers-*"
    setup.ilm.enabled: false
---
apiVersion: apps/v1
kind: DaemonSet 
metadata:
  name: filebeat 
  namespace: elk 
spec:
  selector:
    matchLabels:
      app: filebeat-log
  template:
    metadata:
      labels:
        app: filebeat-log
    spec:
      serviceAccount: filebeat
      containers:
        - args:
            - -c
            - /config/filebeat.yml 
          env:
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
          image: docker.elastic.co/beats/filebeat:8.5.0
          imagePullPolicy: Always
          name: container-log
          volumeMounts:
          - mountPath: /config/filebeat.yml
            name: filebeat-conf
            subPath: filebeat.yml
          - mountPath: /var/log/containers
            name: containerslog
          - mountPath: /var/log/pods 
            name: pods
      volumes:
        - name: filebeat-conf
          configMap:
            name: filebeat
        - name: containerslog
          hostPath: 
            path: /var/log/containers
        - name: pods
          hostPath:
            path: /var/log/pods

http://www.lryc.cn/news/532364.html

相关文章:

  • SQLAlchemy-2.0中模型定义和alembic的数据库迁移工具
  • [含文档+PPT+源码等]精品基于Python实现的django个性化健康餐计划订制系统
  • Python3中异常处理:try/except语句
  • [ Spring] Integrate Spring Boot Dubbo with Nacos 2025
  • 【3分钟极速部署】在本地快速部署deepseek
  • 【QT笔记】使用QScrollArea实现多行文本样式显示
  • 大模型中提到的超参数是什么
  • 【Uniapp-Vue3】z-paging插件组件实现触底和下拉加载数据
  • UE虚幻引擎No Google Play Store Key:No OBB found报错如何处理
  • OKHttp拦截器解析
  • STM32标准库移植RT-Thread nano
  • c++11总结26——std::regex
  • langchain教程-12.Agent/工具定义/Agent调用工具/Agentic RAG
  • leetcode_双指针 125.验证回文串
  • ML.NET库学习001:基于PCA的信用卡异常检查之样本处理与训练
  • 【华为OD机考】华为OD笔试真题解析(1)--AI处理器组合
  • edu小程序挖掘严重支付逻辑漏洞
  • 力扣 279. 完全平方数
  • 鸿蒙生态潮起:开发者的逐浪之旅
  • Diskgenius系统迁移之后无法使用USB启动
  • Kafka 可靠性探究—副本刨析
  • 我的博文天地测试报告
  • EtherCAT主站IGH-- 35 -- IGH之pdo_list.h/c文件解析
  • 嵌入式开发神器:Buildroot的介绍和使用方法
  • JavaScript系列(61)--边缘计算应用开发详解
  • 【LeetCode】day15 142.环形链表II
  • 代理对象与目标对象
  • 【Kubernetes Pod间通信-第3篇】Kubernetes中Pod与ClusterIP服务之间的通信
  • DNN(深度神经网络)近似 Lyapunov 函数
  • 128陷阱