在Rancher的功能下,实现基础设施即代码(IaC)的监控功能
本文介绍了如何通过GitOps工作流来实现在自定义资源的yaml文件中声明的监控定义的持续交付方法。
本次使用的功能有以下两个:
– Rancher 监控功能(Prometheus Operator)v2
– Rancher 持续交付功能
这些功能都是在 Rancher v2.5 中进行 GA 版本发布的。首先,我们将简要介绍这些功能。
牧场监控(Prometheus Operator)v2功能

特点
・基于Prometheus Operator的监控解决方案
・可以通过CRs (自定义资源) 轻松定义自定义指标的收集、警报规则等
・由于所有监控定义都可以在CRs的yaml中定义,因此可以轻松构建基于GitOps的工作流程
详细功能介绍,请参考本文。
或者,请参考这份文档。
牧场连续交付功能

特征
・基于Rancher Fleet的GitOps解决方案
・可以从Git仓库部署应用程序和配置设置到多个集群
・不仅支持单一集群,还支持多集群
・应用程序和配置设置支持Kubernetes YAML、Helm、Kustomize等格式
请查阅此文档以获取详细的功能介绍。
建立IaC的监控
Rancher 监控 v2 的安装
通过Rancher 2.5从应用市场安装Rancher Monitoring v2非常简单。
只需在新的仪表盘屏幕左上角的菜单中选择[Cluster Explorer] -> [Apps & Marketplace],然后安装[Monitoring]即可。

GitOps工作流程的配置

※Git仓库的目录结构如下所示。
gitops/monitoring
├── alert-s2-prom-rule.yaml #Prometheus Rules定義CRs
├── alert-s3-prom-rule.yaml #Prometheus Rules定義CRs
└── prom-app-example
├── example-app-deployment.yaml #example-app(検証用アプリケーション)のデプロイメント
├── example-app-service.yaml #example-appのサービス
├── example-app-service-monitor.yaml #example-appのservice-monitor定義CRs
└── example-app-pod-monitor.yaml #example-appのpod-monitor定義CRs
上述的yaml配置文件部署中,以下应用程序和监控设置将被部署:
– 应用程序:
– 部署:example-app
– 服务:example-app
– 监控:
– Pod监控:example-app-pod-monitor
– 服务监控:example-app-service-monitor
– Prometheus规则:alert-1、alert-2、prometheus-example-rules
请参考此GitHub仓库以获取详细的代码。


总结
通过使用Rancher 2.5的新功能,不仅可以实现应用程序的持续交付,还可以轻松实现基础架构的持续交付。