昨天让kubernetes上的各项监控数据顺利的统一到grafana上,今天就来把服务的log统一集中吧。
关於k8s要如何搜集log主要方法有两种,一是透过sidecar的方式将pod log转发出来,二是利用container会在host上写log的原理用daemonset的pod去搜集log;我今天会用daemonset的做法介绍vector这项专案,并透过vector将log送到loki并在grafana上查询。
由於这个架构物件比较多一些,画了一张架构图来表示彼此之间的关系
架构说明
每个node上有一个daemonset的vector agent搜集metric和log,metric会送到外部的属於这座cluster的vector进行处理,再由grafana搜集呈现出来;log则是送到属於这座cluster的kafka做缓送及持久化储存,再由一座统一管理的vector收下来进行parser及transform的变化依据需求转送到外部储存,集中的log会送一份到loki上并存到minio储存,另外透过grafana指定loki为datasource,这样就可以藉由grafana介面统一查询所有cluster的log了。
那麽就先从最基本的daemonset vector agent开始配置,简易的做法是透过helm安装
添加helm的repo库
helm repo add timberio https://packages.timber.io/helm/latest
编辑vector要使用的value
cat <<-'VALUES' > values.yaml
# The Vector Kubernetes integration automatically defines a
# kubernetes_logs source that is made available to you.
# You do not need to define a log source.
sinks:
# Adjust as necessary. By default we use the console sink
# to print all data. This allows you to see Vector working.
# /docs/reference/sinks/
stdout:
type: console
inputs: ["kubernetes_logs"]
target: "stdout"
encoding: "json"
VALUES
安装
helm install vector timberio/vector-agent \
--namespace vector \
--create-namespace \
--values values.yaml
安装完成後可以发现多了一个叫vector的namespace,并且有一个daemonset在每个node上部署了vector agent,另外也可以观察到vector的namespace内有一个configmap,vector agent就会依据这个configmap的内容去取得他的资料来源(metric、log);在完成ds的配置後,因为要让外部的vector能够取得metric资讯,可以将daemonset设定hostnetwork为true,这样就会在每个node上暴露9090port给外部的vector存取罗。
接续昨天的文章,今天介绍一下Yolo v1的Loss Function,由於在训练的时候我们当然希...
Hashicorp Nomad: Sidecar task 在Day 9. Hashicorp No...
下载打包规划是根据GDPR第20条和加州消费者隐私保护法CCPA (California Consu...
接下来要进到关於撰写程序上的概念学习,这一部分对於接下来要撰写比较长的程序时会非常重要!这边会先简单...
本文将於赛後同步刊登於笔者部落格 有兴趣学习更多 Kubernetes/DevOps/Linux 相...