KubeDoor K8S事件告警系统是一个基于规则驱动的智能告警解决方案,能够根据配置的规则自动检测和处理 Kubernetes 事件,并发送相应的告警通知。
- 🎯 规则驱动: 基于 JSON 配置文件的灵活告警规则
- 🔍 多条件匹配: 支持字段包含/不包含、开头/结尾匹配、数值比较等多种匹配条件
- 🚫 智能过滤: 忽略 DELETED 事件和配置的忽略规则
- 🔄 热重载: 支持运行时重新加载告警规则
- 📱 多渠道通知: 支持企业微信、钉钉、飞书、Slack 等多种告警通知方式
接收到 eventStatus=DELETED 的事件,表示该事件超过TTL时间后没有再次触发,事件被K8S删除。并不是实际触发了事件,所以DELETED 事件不会触发任何告警,同时事件状态会记录到数据库。
告警规则配置文件configmap:kubedoor-master-file-cfg
{
"global_ignore_rules": [
{
"name": "环境过滤规则(排除非生产环境[注意:当前未开启])",
"enabled": false,
"conditions": {
"k8s": {
"not_contains": ["prod"]
}
}
},
{
"name": "常见忽略事件[示例:防止告警规则中有正常事件被匹配到,可以加到忽略规则中]",
"enabled": true,
"conditions": {
"reason": {
"contains": ["BackOffStart", "SuccessfulCreate", "SuccessfulMountVolume"]
}
}
}
],
"alert_rules": [
{
"name": "关键事件告警",
"enabled": true,
"severity": "critical",
"conditions": {
"reason": {
"contains": ["OOM", "NodeNotReady", "Unreachable"]
},
"level": {
"contains": ["Warning"]
}
}
},
{
"name": "健康检查失败告警",
"enabled": true,
"severity": "warning",
"conditions": {
"reason": {
"contains": ["Unhealthy"]
},
"name": {
"not_starts_with": ["deploy-datax-cloud-"]
},
"count": {
"greater_than": 1
}
}
},
{
"name": "资源压力告警",
"enabled": true,
"severity": "warning",
"conditions": {
"reason": {
"contains": ["Pressure", "OutOf", "Evict"]
}
}
}
]
}- 共2个规则组,每个规则组有若干条规则。
- 可以通过
enabled字段控制规则是否开启。 - 触发K8S事件后,先进入
global_ignore_rules规则组,任意一条规则匹配即忽略事件。如果未忽略,则进入alert_rules规则组,第一个匹配的规则生效,即触发告警。**
- global_ignore_rules: 多条忽略规则之间是 OR 关系,任意一条规则匹配即忽略事件。
- alert_rules: 多条告警规则之间是 OR 关系,按数组顺序匹配,第一个匹配的规则生效。
每条规则的 conditions 内的多个字段条件之间是 AND 关系,必须所有条件都满足才算匹配:
{
"conditions": {
"reason": { "contains": ["OOMKilling"] }, // 条件1
"level": { "equals": "Warning" }, // 条件2
"namespace": { "not_contains": ["test"] } // 条件3
}
// 只有当 reason包含OOMKilling AND level等于Warning AND namespace不包含test 时才匹配
}对于同一字段的多个值,关系取决于条件类型:
- contains: 多个值之间是 OR 关系(包含任一值即匹配)
- not_contains: 多个值之间是 AND 关系(不包含任何值才匹配)
- starts_with/ends_with: 多个值之间是 OR 关系
- not_starts_with/not_ends_with: 多个值之间是 AND 关系
| 条件类型 | 说明 | 示例 |
|---|---|---|
contains |
字段包含任一指定值 | {"reason": {"contains": ["OOM", "Failed"]}} |
not_contains |
字段不包含任何指定值 | {"namespace": {"not_contains": ["test", "dev"]}} |
equals |
字段等于指定值 | {"level": {"equals": "Warning"}} |
not_equals |
字段不等于指定值 | {"eventStatus": {"not_equals": "DELETED"}} |
starts_with |
字段以指定值开头 | {"name": {"starts_with": ["deploy-"]}} |
not_starts_with |
字段不以指定值开头 | {"name": {"not_starts_with": ["test-"]}} |
ends_with |
字段以指定值结尾 | {"name": {"ends_with": ["-service", "-pod"]}} |
not_ends_with |
字段不以指定值结尾 | {"name": {"not_ends_with": ["-test", "-debug"]}} |
greater_than |
数值大于(仅 count 字段) | {"count": {"greater_than": 3}} |
less_than |
数值小于(仅 count 字段) | {"count": {"less_than": 10}} |
| 字段名 | 描述 |
|---|---|
| level | 事件级别(Normal/Warning) |
| count | 事件发生次数 |
| kind | 对象的类型 |
| k8s | K8S集群名称 |
| namespace | 命名空间 |
| name | 对象的名称 |
| reason | 事件原因 |
| message | 事件详细消息 |
| reportingComponent | 事件来源 |
| reportingInstance | 来源IP |