简体   繁体   English

是否可以在Kubernetes中重定向日志记录?

[英]Is it possible to redirect logging in Kubernetes?

I am new to Kubernetes and when I used to work with Docker swarm I was able to redirect logging the following way: 我是Kubernetes的新手,当我过去使用Docker swarm时,可以通过以下方式重定向日志记录:

  myapp:
    image: myregistry:443/mydomain/myapp
    deploy:
      mode: global
      restart_policy:
        condition: on-failure
    logging:
      driver: gelf
      options:
        gelf-address: "udp://localhost:12201"
    environment:
      - LOGGING_LEVEL=WARN

this way, instead of consulting logs using docker service logs -f myapp or in this case kubectl logs -f myapp , I would have them redirected to monitor them in a centralised manner (eg using ELK). 这样,我不用使用kubectl logs -f myapp docker service logs -f myapp或在这种情况下kubectl logs -f myapp ,而是将它们重定向到以集中方式监视它们(例如,使用ELK)。

Is this possible with Kubernetes? Kubernetes是否可能? What is the equivalent solution? 什么是等效解决方案?

Thank you for your help 谢谢您的帮助

Yes , there are many solutions both opensource and commerial to send all kubernetes logs ( apps and cluster and everything ) to systems like ELK. 是的,有许多开源和商业解决方案都可以将所有kubernetes日志(应用程序和集群以及所有内容)发送到类似ELK的系统。

Assuming you have the ElasticSearch already setup. 假设您已经设置了ElasticSearch。

We are using FluentBit to send K8S logs to EFK: 我们正在使用FluentBit将K8S日志发送到EFK:

Fluent Bit DaemonSet ready to be used with Elasticsearch on a normal Kubernetes Cluster Fluent Bit DaemonSet准备与普通Kubernetes集群上的Elasticsearch一起使用

https://github.com/fluent/fluent-bit-kubernetes-logging https://github.com/fluent/fluent-bit-kubernetes-logging

We are also using SearchGurard with ELk to Restrict users to see logs that belong to apps running in thier own namespaces only. 我们还使用带有ELk的SearchGurard来限制用户查看仅在自己的名称空间中运行的应用程序的日志。

The ELK stack is a very common approach to log aggregation and indexing. ELK堆栈是一种非常常见的日志聚合和索引编制方法。 There are many great tutorials on deploying this stack onto Kubernetes, or you can go with this stable helm chart that installs everything with one command: 有很多很棒的教程将这个堆栈部署到Kubernetes上,或者您可以使用这个稳定的头盔图来通过一个命令安装所有内容:

https://github.com/helm/charts/tree/master/stable/elastic-stack https://github.com/helm/charts/tree/master/stable/elastic-stack

You can tweak your deployment via the values.yaml if you haven't worked with Helm before. 如果您以前没有使用过Helm,则可以通过values.yaml调整部署。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM