目录
- 导航
- 前言
- 相关yaml文件
-
- 权限相关
-
- alertmanager-serviceAccount.yaml
- 配置相关
-
- alertmanager-secret.yaml
- 服务相关
-
- alertmanager-service.yaml
- alertmanager-service-web.yaml
- alertmanager.yaml
- 部署
- 验证
导航
进阶之路:从零到一在k8s上部署高可用prometheus —— 总览
进阶之路:从零到一在k8s上部署高可用prometheus —— 准备工作
进阶之路:从零到一在k8s上部署高可用prometheus —— exporter
进阶之路:从零到一在k8s上部署高可用prometheus —— consul
进阶之路:从零到一在k8s上部署高可用prometheus —— prometheus-operator
进阶之路:从零到一在k8s上部署高可用prometheus —— prometheus
进阶之路:从零到一在k8s上部署高可用prometheus —— alertmanager
进阶之路:从零到一在k8s上部署高可用prometheus —— minio
进阶之路:从零到一在k8s上部署高可用prometheus —— thanos receive、thanos query
前言
在上一章部署完监控基础组件prometheus
后,我们应该已经可以采集到node_exporter暴露出的监控数据了。但是仅仅有数据是不够的,我们需要将数据转化为可以利用的资源,常见的监控数据应用方向有两个 —— 监控可视化
和告警
。本章主要讲述如何通过alertmanager
以告警的方式利用监控数据。
相关yaml文件
权限相关
alertmanager-serviceAccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:name: alertmanager-ifcloud
配置相关
alertmanager-secret.yaml
# 由于我没有准备用于接收告警的webhook,这里只放了一个官方示例,并没有任何实际用途,实际使用请参考:https://prometheus.io/docs/alerting/latest/alertmanager/
apiVersion: v1
kind: Secret
metadata:name: alertmanager-ifcloud
stringData:alertmanager.yaml: |-"global":"resolve_timeout": "5m""inhibit_rules":- "equal":- "namespace"- "alertname""source_match":"severity": "critical""target_match_re":"severity": "warning|info"- "equal":- "namespace"- "alertname""source_match":"severity": "warning""target_match_re":"severity": "info""receivers":- "name": "Default"- "name": "Watchdog"- "name": "Critical""route":"group_by":- "namespace""group_interval": "5m""group_wait": "30s""receiver": "Default""repeat_interval": "12h""routes":- "match":"alertname": "Watchdog""receiver": "Watchdog"- "match":"severity": "critical""receiver": "Critical"
type: Opaque
服务相关
alertmanager-service.yaml
apiVersion: v1
kind: Service
metadata:labels:alertmanager: ifcloudname: alertmanager-ifcloud
spec:ports:- name: webport: 9093targetPort: webselector:alertmanager: ifcloudapp: alertmanagersessionAffinity: ClientIP
alertmanager-service-web.yaml
kind: Service
apiVersion: v1
metadata:name: alertmanager-ifcloud-weblabels:app: alertmanager-ifcloud-web
spec:ports:- name: http-webprotocol: TCPport: 9093targetPort: 9093nodePort: 30004selector:alertmanager: ifcloudapp: alertmanagertype: NodePortsessionAffinity: None
alertmanager.yaml
apiVersion: monitoring.coreos.com/v1
kind: Alertmanager #prometheus-operator提供的crd
metadata:labels:alertmanager: ifcloudname: ifcloud
spec:image: quay.io/prometheus/alertmanager:v0.21.0nodeSelector:kubernetes.io/os: linuxreplicas: 3securityContext:fsGroup: 2000runAsNonRoot: truerunAsUser: 1000serviceAccountName: alertmanager-ifcloudversion: v0.21.0
部署
# 将以上文件放在目录/yaml/alertmanager下
# 执行以下命令验证yaml文件正确性
kubectl apply -f /yaml/alertmanager -n prom-ha --dry-run=client# 验证无误后执行以下命令创建相关k8s资源
kubectl apply -f /yaml/alertmanager -n prom-ha
验证
部署完成后访问http://192.168.25.80:30004/#/alerts,等待一段时间后我们应该可以看到上章配置的prometheusRule触发的告警。