在CentOS上设置K8s监控与告警,常用方案是Prometheus+Grafana+Alertmanager,具体步骤如下:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
,再安装helm install prometheus prometheus-community/prometheus -n monitoring
,可通过修改values.yaml
配置抓取目标等参数。helm install grafana grafana/grafana -n monitoring
,安装后在Grafana界面添加Prometheus数据源,填入服务地址即可展示监控数据。helm install alertmanager prometheus-community/alertmanager -n monitoring
,创建alertmanager-config.yaml
配置文件,设置告警规则、接收方式等,将其作为Secret对象存储,然后在部署Alertmanager时引用。groups
和rules
定义告警规则,如监控CPU使用率、Pod重启次数等,示例规则为- alert: HighCpuUsage
,当容器CPU使用率超过85%持续2分钟时触发告警。