在k8s中,可以使用以下方法获取日志:

  1. 使用kubectl logs命令获取容器日志:
kubectl logs <pod-name> <container-name>

其中,pod-name是要获取日志的Pod名称,container-name是要获取日志的容器名称。

  1. 在k8s中使用DaemonSet部署filebeat,通过filebeat采集容器日志并发送到指定的输出端。

在filebeat部署文件中配置input部分,指定要采集的容器日志路径:

- type: container
  paths:
    - /var/log/containers/*.log

然后,在output部分配置要发送到的输出端,例如Elasticsearch、Logstash等:

output.elasticsearch:
  hosts: ["elasticsearch:9200"]

最后,在k8s中部署filebeat DaemonSet:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: filebeat
spec:
  selector:
    matchLabels:
      app: filebeat
  template:
    metadata:
      labels:
        app: filebeat
    spec:
      containers:
      - name: filebeat
        image: docker.elastic.co/beats/filebeat:7.15.0
        volumeMounts:
        - name: varlogcontainers
          mountPath: /var/log/containers
          readOnly: true
        - name: config
          mountPath: /usr/share/filebeat/filebeat.yml
          subPath: filebeat.yml
          readOnly: true
      volumes:
      - name: varlogcontainers
        hostPath:
          path: /var/log/containers
      - name: config
        configMap:
          name: filebeat-config
``
k8s里面filebeat怎么获取日志

原文地址: https://www.cveoy.top/t/topic/g93G 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录