一、介绍
Operator是CoreOS公司开发,用于扩展kubernetes API或特定应用程序的控制器,它用来创建、配置、管理复杂的有状态应用,例如数据库,监控系统。其中Prometheus-Operator就是其中一个重要的项目。
其中核心部分是Operator,它会去创建Prometheus、ServiceMonitor、AlertManager、PrometheusRule这4个CRD对象,然后会一直监控并维护这4个对象的状态。
Prometheus:作为Prometheus Server的抽象
ServiceMonitor:就是exporter的各种抽象
AlertManager:作为Prometheus AlertManager的抽象
PrometheusRule:实现报警规则的文件
上图中的 Service 和 ServiceMonitor 都是 Kubernetes 的资源,一个 ServiceMonitor 可以通过 labelSelector 的方式去匹配一类 Service,Prometheus 也可以通过 labelSelector 去匹配多个ServiceMonitor。
二、安装
安装方式:通过源码安装
git clone https://github.com/coreos/kube-prometheus.git
(通过源码安装可能会导致集群权限不足的问题出现)
可参考 如下:
git clone https://gitee.com/Tsail/kube-prometheus.git
cat manifests/alertmanager-secret.yaml
cat manifests/setup/prometheus-operator-clusterRole.yaml
cd kube-prometheus/manifests/ServiceMonitor && ls
相关配置可进行优化调整。
我们进入kube-prometheus/manifests/setup,就可以直接创建CRD对象:
# cd kube-prometheus/manifests/setup
# kubectl apply -f .
然后在上层目录创建资源清单:
# cd kube-prometheus/manifests
# kubectl apply -f .
可以看到创建如下的CRD对象:
[root@jdo-dev-k8s-master-90 ~]# kubectl get crd | grep coreos
alertmanagers.monitoring.coreos.com 2021-08-19T10:45:23Z
podmonitors.monitoring.coreos.com 2021-08-19T10:45:23Z
prometheuses.monitoring.coreos.com 2021-08-19T10:45:23Z
prometheusrules.monitoring.coreos.com 2021-08-19T10:45:24Z
servicemonitors.monitoring.coreos.com 2021-08-19T10:45:24Z
查看创建的po