k8s 日志的收集

Posted lulin9501

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s 日志的收集相关的知识,希望对你有一定的参考价值。

filebeat的ConfigMap的文件

[root@laso yaml]# cat configmap.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: filebeat-config
data:
  filebeat.yml: |
    filebeat.prospectors:
    - input_type: log
      paths:
        - "/log/*"
      fields:
        type: "filebeta"
    output.logstash:
      hosts: ["192.168.199.224:5044"]

java项目的pod

[root@laso yaml]# cat deployment_consumer.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: consumer
  namespace: default
spec:
  replicas: 1
  selector:  
    matchLabels:
      app: consumer
      release: beta
  template: 
    metadata:
      labels:
        app: consumer
        release: beta
    spec:
      #nodeSelector:
      #  env: beta
      terminationGracePeriodSeconds: 40
      containers: # pod
      - name: filebeta
        image: registry.cn-beijing.aliyuncs.com/cn_genebox/filebeat:v7
        volumeMounts:
        - name: app-logs
          mountPath: /log
        - name: filebeat-config
          mountPath: /etc/filebeat/
      - name: consumer
        image: registry.cn-beijing.aliyuncs.com/cn_genebox/consumer:v1.0.4
        imagePullPolicy: Always
        ports: 
        - name: port
          containerPort: 8022
        readinessProbe:
          httpGet:
            port: port  #也可以使用80
            path: /smoketest
          initialDelaySeconds: 3 #容器启动后等待1秒开始探测
          periodSeconds: 2 #每隔3秒探测一次       
        livenessProbe:
          httpGet:
            port: port  #也可以使用80
            path: /smoketest
          initialDelaySeconds: 10 #容器启动后等待10秒开始探测
          periodSeconds: 2 #每隔3秒探测一次
        volumeMounts:
         - name: app-logs
           mountPath: /tmp/laso/logs/consumer
      # 拉取容器的账户密码
      imagePullSecrets:
      - name: registry-secret
      # 挂载卷
      volumes:
      - name: app-logs
        hostPath:
         path: /log/consumer   # node主机的/log/consumer挂载在 pod的/tmp/laso/logs/consumer上
         type: DirectoryOrCreate # 目录不存在创建
      # -  name: app-logs
      #   nfs:
      #     path: /home/nfs
      #     server: 192.168.199.226
       #   #type: DirectoryOrCreate
      - name: filebeat-config
        configMap:
          name: filebeat-config

 

以上是关于k8s 日志的收集的主要内容,如果未能解决你的问题,请参考以下文章

k8s 日志收集之 EFK

k8s 日志收集之 EFK

K8S日志收集方案实践

k8s-日志落地

k8s日志收集解决方案

k8s日志收集 - 利用HOSTNAME环境变量对多个pod挂载不同目录方案