
Prometheus 是 CNCF 中已经毕业的项目之一,主要用于监控和告警。在 Kubernetes 生态中,它是应用最为广泛的监控和告警工具之一。Rancher 用户可以通过使用内置的监控堆栈(https://rancher2.docs.rancher.cn/docs/cluster-admin/tools/monitoring/_index)来快速利用 Prometheus。
Prometheus 将其指标(metrics)作为时序数据库存储在本地磁盘上,因此 Prometheus 的本地存储会受到磁盘大小以及所能保留的指标数量的制约。但是,Prometheus 允许与远程系统集成,通过_remotewrite 和_remoteread 指令读写指标,同时它还支持大量远程端点和存储集成:
https://prometheus.io/docs/operating/integrations/#remote-endpoints-and-storage
联邦可以实现可扩展的 Prometheus 监控设置,或者将相关的指标从一个服务的 Prometheus 拉取到另一个 Prometheus 中。
在本文中,我们将探索一个快速和简单的方式来设置 Rancher 监控远程端点与 Thanos receive 的集成。Thanos 是一个开源的、高可用的 Prometheus 设置,有长期指标存储功能。你可以使用这个解决方案在所有的 Prometheus 实例中实现联邦指标,并允许中央 Grafana dashboard 在 Thanos 上运行。
重要提醒:作为指标联邦的一部分,项目/集群指标将不在 Rancher 管理平面内。此外,集群管理员必须确保建立适当的访问控制机制,以限制对该指标存储的访问。
安装 Thanos
在本篇文章中,我们可以使用 kube-thanos(https://github.com/thanos-io/kube-thanos)在 Kubernetes 集群上快速设置 Thanos。
我们将需要以下 Thanos 组件:
Thanos 存储 gateway
Thanos 接收器(receiver)
Thanos 查询器(querier)
对象存储
该解决方案如下所示:
来源:Thanos receive proposal
https://github.com/thanos-io/thanos/blob/master/docs/proposals/201812_thanos-remote-receive.md
Thanos 支持若干对象存储配置:
https://thanos.io/storage.md/#configuration
我们将使用 MinIO 作为我们的对象存储。你需要在名为 thanos-objectStorage 的 secret 中定义对象存储,它需要在你的 Thanos deployment 命名空间中。
thanos-config.yaml
如下所示:
你可以按照以下方式创建 secret:
kubectl create secret generic thanos-objectstorage --from-file=thanos.yaml="$PATH_TO_CONFIG"/thanos-config.yaml
配置 Rancher 监控
与 Rancher 监控 operator 打包的 Prometheus 版本已经支持 remote_read 和 remote_write 集成。
Thanos receive endpoint 的额外设置可以通过高级选项传递,如下所示:

我们需要按照 Prometheus remote_write 规范的要求,指定一个唯一的名字。
你完成了监控的部署之后,你应该可以使用 Thanos 查询器查看你的指标。

已存储的指标也将在对象存储中获取。

由于所有的集群指标在这个 Thanos 安装中都是可用的,所以工作负载的所有者需要确保对工作负载和指标的访问是安全的。
总结
使用 Rancher 监控(即 Prometheus)和 Thanos 接收器中的远程读写功能,你可以通过几个简单的步骤就能够实现长期指标存储和多个集群指标的全局视图。而在 Rancher 企业版中已经默认集成了多集群全局监控,你可以获得更直观更方便的全局监控体验。如果你想进一步了解 Rancher 企业版的其他特性,欢迎扫描文末二维码咨询小助手。

本文转载自公众号 RancherLabs(ID:RancherLabs)。
原文链接:
https://mp.weixin.qq.com/s/rmPmwAR_DUplSnzEHV8Rjw
评论