溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Kube-Eventer的操作介紹

發布時間:2021-06-22 14:04:26 來源:億速云 閱讀:163 作者:chen 欄目:web開發

這篇文章主要介紹“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的開掛技巧。首先看支持的參數:

  • level - Level of event (optional. default: Warning. Options: Warning and  Normal)

  • namespaces - Namespaces to filter (optional. default: all namespaces,use  commas to separate multi namespaces, namespace filter doesn't support  regexp)

  • kinds - Kinds to filter (optional. default: all kinds,use commas to separate  multi kinds. Options: Node,Pod and so on.)

  • reason - Reason to filter (optional. default: empty, Regexp pattern support).  You can use multi reason fields in query.

  • method - Method to send request (optional. default: GET)

  • header - Header in request (optional. default: empty). You can use multi  header field in query.

  • custom_body_configmap - The configmap name of request body template. You can  use Template to customize request body. (optional.)

  • custom_body_configmap_namespace - The configmap namespace of request body  template.

如果每個項目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的操作介紹”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女