Kubernetes结合Prometheus Operator 配置邮件报警

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_33430322/article/details/89349827

简述

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

腾讯邮箱配置

在这里插入图片描述
设置-账户 如上图所示开启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: "xxxxxxxx@qq.com"   #发送邮箱的地址   例子:122334444@qq.com
  smtp_auth_username: "xxxxxxxx@qq.com"   #发送邮箱的用户    例子:122334444@qq.com
  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: edwinghu@163.com                                   #接受报警邮箱的地址
    headers: { Subject: "[WARN] 报警邮件" }         #接受报警的头

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

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

单机配置邮件报警
在这里插入图片描述

参考

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

展开阅读全文

没有更多推荐了,返回首页