Kubernetes结合Prometheus Operator 配置邮件报警

Kubernetes结合Prometheus Operator 配置邮件报警

  • 简述
  • 腾讯邮箱配置
  • prometheus-operator配置邮件发送
  • alertmanager-secret.yaml文件修改
  • 参考

简述

因为25端口被阿里云禁用,开启比较麻烦,可以尝试用腾讯邮箱SSL加密方式发送邮件。

腾讯邮箱配置

Kubernetes结合Prometheus Operator 配置邮件报警_第1张图片
设置-账户 如上图所示开启IMAP/SMTP服务 获取授权码

prometheus-operator配置邮件发送

git clone https://github.com/coreos/prometheus-operator.git

prometheus-operator\contrib\kube-prometheus\manifests\alertmanager-secret.yaml

alertmanager-secret.yaml文件修改

apiVersion: v1
data:
  alertmanager.yaml: Imdsb2JhbCI6IAogICJyZXNvbHZlX3RpbWVvdXQiOiAiNW0iCiJyZWNlaXZlcnMiOiAKLSAibmFtZSI6ICJudWxsIgoicm91dGUiOiAKICAiZ3JvdXBfYnkiOiAKICAtICJqb2IiCiAgImdyb3VwX2ludGVydmFsIjogIjVtIgogICJncm91cF93YWl0IjogIjMwcyIKICAicmVjZWl2ZXIiOiAibnVsbCIKICAicmVwZWF0X2ludGVydmFsIjogIjEyaCIKICAicm91dGVzIjogCiAgLSAibWF0Y2giOiAKICAgICAgImFsZXJ0bmFtZSI6ICJXYXRjaGRvZyIKICAgICJyZWNlaXZlciI6ICJudWxsIg==
kind: Secret
metadata:
  name: alertmanager-main
  namespace: monitoring
type: Opaque

拿到配置内容,用base64反解alertmanager.yaml一下,默认配置如下:

# echo "加密的内容" | base64 -d
"global": 
  "resolve_timeout": "5m"
"receivers": 
- "name": "null"
"route": 
  "group_by": 
  - "job"
  "group_interval": "5m"
  "group_wait": "30s"
  "receiver": "null"
  "repeat_interval": "12h"
  "routes": 
  - "match": 
      "alertname": "Watchdog"
    "receiver": "null"

添加自己的邮件配置,因为邮件发送需要有个发件人和收件人,目前我们用的是alertmanager的配置

global:
  resolve_timeout: 5m
  smtp_smarthost: "smtp.qq.com:465"   
  # 默认端口这个在qq邮箱配置中可以看到,默认端口是端口号465或587
  # qq官方帮助文档  https://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=331
  smtp_from: "[email protected]"   #发送邮箱的地址   例子:[email protected]
  smtp_auth_username: "[email protected]"   #发送邮箱的用户    例子:[email protected]
  smtp_auth_password: "ukpoqrbeoteibhee"  #发送邮箱的授权码    
  smtp_require_tls: false
route:
  group_by: ['alertname']
  repeat_interval: 1h
  receiver: live-monitoring
receivers:
- name: live-monitoring
  email_configs:
  - to: [email protected]                                   #接受报警邮箱的地址
    headers: { Subject: "[WARN] 报警邮件" }         #接受报警的头

用base64加密下替换后,按照部署步骤基本就ok。部署指导可以参考:

https://blog.csdn.net/qq_33430322/article/details/89189766

单机配置邮件报警
Kubernetes结合Prometheus Operator 配置邮件报警_第2张图片

参考

https://github.com/coreos/prometheus-operator

你可能感兴趣的:(Kubernetes结合Prometheus Operator 配置邮件报警)