首页 > 其他分享 >k8s 日志收集

k8s 日志收集

时间:2023-07-21 14:22:18浏览次数:40  
标签:filebeat name 收集 app1 demoapp log 日志 k8s metadata

日志收集流程

filebeat--->kafka--->logstash--->elasticsearch

logstash.conf

input {
  kafka {
    bootstrap_servers => "172.16.3.213:19092,172.16.3.213:29092,172.16.3.213:39092"
    topics => ["app-1"]
    codec => "json"
  }
}

output {
  if [fields][source] == "app1" {
    elasticsearch {
      hosts => ["https://172.16.3.9:9200"]
      index => "app1-%{+YYYY.MM.dd}"
      user => "xxxxxxx"
      password => "xxxxxxx"
      cacert => "/usr/share/logstash/config/ca.crt" 
    }
  }

}

filebeat-app1-conf.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: filebeat-app1-config
  namespace: demoapp
data:
  filebeat.yml: |
    filebeat.inputs:
    - type: filestream
      id: app1
      enabled: true
      paths:
        - /var/log/1.log
      fields:
        source: app1

    filebeat.config.modules:
      path: ${path.config}/modules.d/*.yml
      reload.enabled: false

    processors:
    - add_host_metadata:
        when.not.contains.tags: forwarded
    #- add_cloud_metadata: ~
    #- add_docker_metadata: ~
    #- add_kubernetes_metadata: ~

    output.kafka:
      hosts: ["172.16.3.213:19092", "172.16.3.213:29092", "172.16.3.213:39092"]
      topic: 'app-1'   
      partition.round_robin:
        reachable_only: false

      required_acks: 1
      compression: gzip
      max_message_bytes: 1000000

demo-ns.yaml

apiVersion: v1
kind: Namespace
metadata:
    name: demoapp

depoly-demo.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: demoapp-deployment
  namespace: demoapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: demoapp
      controller: demoapp
  template:
    metadata:
      labels:
        app: demoapp
        controller: demoapp
    spec:
      containers:
      - name: demoapp
        image: busybox:1.28
        ports:
        - containerPort: 80
          name: http
        args:
        - /bin/sh
        - -c
        - >
          i=0;
          while true;
          do
            echo "$i: $(date)" >> /var/log/1.log;
            echo "$(date) INFO $i" >> /var/log/2.log;
            i=$((i+1));
            sleep 1;
          done      
        resources:
          requests:
            memory: "256Mi"
            cpu: "50m"
          limits:
            memory: "256Mi"
            cpu: "50m"
        volumeMounts:
        - name: varlog
          mountPath: /var/log	
      - name: filebeat
        image: docker.elastic.co/beats/filebeat:8.7.0
        resources:
          requests:
            memory: "256Mi"
            cpu: "50m"
          limits:
            memory: "256Mi"
            cpu: "50m"
        volumeMounts:
        - name: varlog
          mountPath: /var/log	
        - name: config-volume
          mountPath: /usr/share/filebeat/filebeat.yml
          subPath: filebeat.yml
      volumes:
      - name: varlog
        emptyDir: {}
      - name: config-volume
        configMap:
          name: filebeat-app1-config


---
apiVersion: v1
kind: Service
metadata:
  name: demoapp-svc
  namespace: demoapp
spec:
  selector:
    app: demoapp
    controller: demoapp
  ports:
  - name: http
    port: 80
    targetPort: 80

创建demo资源

# kubectl apply -f demo-ns.yaml -f filebeat-app1-conf.yaml -f depoly-demo.yaml

查看kafka数据

查看es索引

查看日志信息

标签:filebeat,name,收集,app1,demoapp,log,日志,k8s,metadata
From: https://www.cnblogs.com/wangguishe/p/17566035.html

相关文章

  • python2发送日志到es
    如何用Python2发送日志到ES一、流程概述以下是将日志发送到Elasticsearch(ES)的整个流程,包括准备工作和代码实现。我们将使用Python2来完成这个任务。步骤描述1.准备环境安装所需的Python依赖库和Elasticsearch2.连接ES使用Python代码连接到Elasticsearch3.创......
  • Linux删除log日志文件命令
    如下:1、删除文件夹及子目录下的日志文件find.-name'*.log*'|xargsrm2、忽略当前文件夹下的文件夹,可在-v后面添加  “/文件夹名称”,这里用log文件夹举例find.-name'*.log*'|grep-v/log|xargsrm这样就可以删除总文件夹下除了log文件夹以外的.log文件了......
  • windows mysql 启动日志
    实现"WindowsMySQL启动日志"的步骤下面是实现"WindowsMySQL启动日志"的步骤的表格示例:步骤描述1安装MySQL服务器2配置MySQL服务器启动参数3设置MySQL服务器日志输出4启动MySQL服务器接下来,我们将逐步解释每个步骤应该如何执行。步骤1:安......
  • 学习日志
    7.20今天主要是复习了以前的知识点,顺便做了一道递归入门题斐波那契数列#include<bits/stdc++.h>usingnamespacestd;intfbnq(intm){ if(m==1||m==2){ return1; }else{ if(m<1)return0; elsereturnfbnq(m-1)+fbnq(m-2); }}intn;intmain(){ cin>>n;......
  • [日志] 日志脱敏实践
    1序言思路:根据待输出的关键字段名称进行不可逆算法的(离线式)脱敏。2步骤2.1修改本工程的日志框架为Log4j2slf4j.version=1.7.25log4j.version=2.13.3<!--log[start]--><dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <ve......
  • 搬运 -阮一峰的网络日志 --Flex 布局教程:实例篇
    原文链接:http://www.ruanyifeng.com/blog/2015/07/flex-examples.html语法: https://www.cnblogs.com/yuwen1995/p/17568483.html一、骰子的布局骰子的一面,最多可以放置9个点。下面,就来看看Flex如何实现,从1个点到9个点的布局。你可以到codepen查看Demo。如果不加说明,本节的......
  • filebeat.yaml(k8s configmap)部署清单
    apiVersion:v1kind:ConfigMapmetadata:name:bh-shard-2-filebeat-confignamespace:bluehelixlabels:app:bh-shard-2-testapp.kubernetes.io/managed-by:Helmchart:java-0.9.9heritage:Helmrelease:bluehelix-bh-shard-2data:......
  • 【容器架构】你知道有 Docker 为什么还要 K8s 吗?
    ......
  • cms和g1垃圾收集器
    一、cms垃圾收集器 jdk1.5之后出现在标记清理方法上做优化1、初始标记2、并发标记3、重新标记4、并发清除在1、3会StopTheWorld 描述:初始标记仅仅只是标记GCRoot可以直接关联到的对象,速度很快。并发标记是进行GCRoottracting的过程,重新标记是为了修正并发标记的......
  • k8s挂在docker目录
    在Docker中挂载Kubernetes目录的步骤介绍在Kubernetes(简称K8s)中,我们可以使用Volume挂载来实现在Pod中访问宿主机上的目录。本文将指导你如何在Docker中挂载Kubernetes目录。步骤概述下表展示了完成此任务的步骤概述:步骤描述步骤1创建一个KubernetesPod步骤2......