Kube-Eventer的操作介绍

发布时间:2021-06-22 14:04:26 作者:chen
来源:亿速云 阅读:134

这篇文章主要介绍“Kube-Eventer的操作介绍”,在日常操作中,相信很多人在Kube-Eventer的操作介绍问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Kube-Eventer的操作介绍”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

离线事件告警

kube-eventer是由阿里开源的k8s离线事件收集器,开源地址

https://github.com/AliyunContainerService/kube-eventer/blob/master/docs/en/webhook-sink.md

在Kubernetes中,事件分为两种,一种是Warning事件,表示产生这个事件的状态转换是在非预期的状态之间产生的;另外一种是Normal事件,表示期望到达的状态,和目前达到的状态是一致的。

我们以NPD的event来讲解。事件影响节点的临时性问题,但是它是对于系统诊断是有意义的。NPD就是利用kubernetes的上报机制,通过检测系统的日志(例如centos中journal),把错误的信息上报到kuberntes的node上。这些日志(例如内核日志)中噪音信息太多,NPD会提取其中有价值的信息,可以将这些信息生成离线事件。这样我就可以得到node上的时间,及时进行处理。

一个标准的Kubernetes事件有如下几个重要的属性,通过这些属性可以更好地诊断和告警问题。Namespace:产生事件的对象所在的命名空间。

Kind:绑定事件的对象的类型,例如:Node、Pod、Namespace、Componenet等等。

Timestamp:事件产生的时间等等。

Reason:产生这个事件的原因。Message: 事件的具体描述。

Kube-Eventer的操作介绍

目前的sinks支持大致如下:

Sink NameDescription
dingtalksink to dingtalk bot
slssink to alibaba cloud sls service
elasticsearchsink to elasticsearch
honeycombsink to honeycomb
influxdbsink to influxdb
kafkasink to kafka
mysqlsink to mysql database
wechatsink to wechat

今天主要带来webhook的开挂技巧。首先看支持的参数:

如果每个项目namespace与负责人是一一对应的,就可以根据configmap与sink关联起来。变更上线部署是最容易出现事件的时候,通过事件是可以快速的发现上线的镜像tag错误,镜像配置错误等问题。

首先configmap,通过custom_body_configmap的值来选择不同的配置文件。可以简单修饰一下,使其变得更加清晰。

添加加Cluster:name可以知道是哪个集群的event。

添加加"mentioned_list":["wangqin","@all"]可以@对应的负责人。

--- apiVersion: v1 data:   content: >-        {"msgtype": "text","text": {"content": "Cluster:name\nEventType:{{ .Type }}\nEventNamespace:{{ .InvolvedObject.Namespace }}\nEventKind:{{ .InvolvedObject.Kind }}\nEventObject:{{ .InvolvedObject.Name }}\nEventReason:{{ .Reason }}\nEventTime:{{ .LastTimestamp }}\nEventMessage:{{ .Message }}","mentioned_list":["wangqing","@all"]}} kind: ConfigMap metadata:   name: custom-webhook-body   namespace: nameapce

命令部分的技巧

sink是一个数组,可以加很多条。

主要说明用webhook向企业微信的的通知。注意reason是可以支持正则表达式的。通过configmap就一起完成了k8s机器的事件告警。

command:   - "/kube-eventer"   - "--source=kubernetes:https://kubernetes.default"   ## .e.g,dingtalk sink demo  - --sink=webhook:https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxx&level=Warning&reason=[^Unhealthy]&namespaces=xxxx&header=Content-Type=application/json&custom_body_configmap=custom-webhook-body0&custom_body_configmap_namespace=xxxx&method=POST  - --sink=webhook:https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxx&level=Warning&reason=BackOff&namespaces=xxxx&header=Content-Type=application/json&custom_body_configmap=custom-webhook-body1&custom_body_configmap_namespace=xxxx&method=POST  - --sink=webhook:https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxx&level=Warning&reason=Failed&namespaces=xxxx&header=Content-Type=application/json&custom_body_configmap=custom-webhook-body2&custom_body_configmap_namespace=xxxxx&method=POST

案列:

创建一个企业微信群的机器人。比如:https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxx。

apiVersion: apps/v1 kind: Deployment metadata:   labels:     name: kube-eventer   name: kube-eventer   namespace: namespace spec:   replicas: 1   selector:     matchLabels:       app: kube-eventer   template:     metadata:       labels:         app: kube-eventer       annotations:          scheduler.alpha.kubernetes.io/critical-pod: ''     spec:       dnsPolicy: ClusterFirstWithHostNet       serviceAccount: kube-eventer       containers:         - image: registry.aliyuncs.com/acs/kube-eventer-amd64:v1.2.0-484d9cd-aliyun           name: kube-eventer           command:             - "/kube-eventer"             - "--source=kubernetes:https://kubernetes.default"             ## .e.g,dingtalk sink demo             - --sink=webhook:https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxx&level=Warning&reason=[^Unhealthy]&namespaces=xxxx&header=Content-Type=application/json&custom_body_configmap=custom-webhook-body0&custom_body_configmap_namespace=xxxx&method=POST             #- --sink=webhook:https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxx&level=Warning&reason=BackOff&namespaces=xxxx&header=Content-Type=application/json&custom_body_configmap=custom-webhook-body1&custom_body_configmap_namespace=xxxx&method=POST             #- --sink=webhook:https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxx&level=Warning&reason=Failed&namespaces=xxxx&header=Content-Type=application/json&custom_body_configmap=custom-webhook-body2&custom_body_configmap_namespace=xxxxx&method=POST           env:           # If TZ is assigned, set the TZ value as the time zone           - name: TZ             value: "Asia/Shanghai"            volumeMounts:             - name: localtime               mountPath: /etc/localtime               readOnly: true             - name: zoneinfo               mountPath: /usr/share/zoneinfo               readOnly: true           resources:             requests:               cpu: 200m               memory: 100Mi             limits:               cpu: 500m               memory: 250Mi       volumes:         - name: localtime           hostPath:             path: /etc/localtime         - name: zoneinfo           hostPath:             path: /usr/share/zoneinfo --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata:   name: kube-eventer rules:   - apiGroups:       - ""     resources:       - events       - configmaps     verbs:       - get       - list       - watch --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata:   name: kube-eventer roleRef:   apiGroup: rbac.authorization.k8s.io   kind: ClusterRole   name: kube-eventer subjects:   - kind: ServiceAccount     name: kube-eventer     namespace: namespace --- apiVersion: v1 kind: ServiceAccount metadata:   name: kube-eventer   namespace: namespace  --- apiVersion: v1 data:   content: >-        {"msgtype": "text","text": {"content": "Cluster:name\nEventType:{{ .Type }}\nEventNamespace:{{ .InvolvedObject.Namespace }}\nEventKind:{{ .InvolvedObject.Kind }}\nEventObject:{{ .InvolvedObject.Name }}\nEventReason:{{ .Reason }}\nEventTime:{{ .LastTimestamp }}\nEventMessage:{{ .Message }}","mentioned_list":["wangqing","@all"]}} kind: ConfigMap metadata:   name: custom-webhook-body   namespace: nameapce

这样就可以完成向谁告警,谁进行处理的简单分配。有了事件告警,可以及时发现服务问题与集群问题并进行修复。

到此,关于“Kube-Eventer的操作介绍”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

推荐阅读:
  1. zabbix监控的介绍和操作
  2. Flume的介绍和简单操作

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

上一篇:HTTP/1.x 的 keep-alive与 HTTP/2 多路复用的区别是什么?

下一篇:Arch Linux如何安装

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》