背景
在 Kubernetes 開源生態中,資源監控有 metrics-server、Prometheus等,但這些監控並不能實時推送 Kubernetes 事件,監控準確性也不足。當 kubernetes 叢集中發生 Pod因為 OOM 、拉取不到映象、健康檢查不通過等錯誤導致重啟,叢集管理員其實是不知道的,因為 Kubernetes 有自我修復機制,Pod宕掉,可以重新啟動一個。這樣讓叢集管理員很難立即發現服務問題。
Kubernetes 事件Kubernetes中,事件分為兩種:
Warning事件:表示產生這個事件的狀態轉換是在非預期的狀態之間產生的Normal事件:表示期望到達的狀態,和目前達到的狀態是一致的例子:
$ kubectl get eventsLAST SEEN TYPE REASON OBJECT MESSAGE58m Normal ScalingReplicaSet deployment/demo Scaled down replica set demo-8b85c64cb to 05m7s Warning Unhealthy pod/demo-79844f78b8-nd5jz Readiness probe failed: Get http://192.168.1.68:8080/healthCheck: dial tcp 192.168.1.68:8080: connect: connection refused
如何監聽k8s事件並通知?阿里雲開源 Kubernetes 事件離線工具 kube-eventer,能很好的解決這個問題。
kube-eventer 簡介kube-eventer 是一個事件發射器,它將 kubernetes 事件傳送到接收器(例如dingtalk,sls,kafka,微信等)。kubernetes 的核心設計概念是狀態機。因此,Normal 當轉移到所需狀態時會有事件 Warning。
用法下面是以 釘釘 做為接收器,通過釘釘機器人通知到相關人員或者相關群
獲取釘釘群機器人 Token,如下圖安裝事件處理程式並配置接收器
apiVersion: apps/v1beta2kind: Deploymentmetadata: labels: name: kube-eventer name: kube-eventer namespace: kube-systemspec: 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.1.0-63e7f98-aliyun name: kube-eventer command: - "/kube-eventer" - "--source=kubernetes:https://kubernetes.default" ## .e.g,dingtalk sink demo - --sink=dingtalk:[your_webhook_url]&label=[your_cluster_id]&level=[Normal or Warning (default)] env: # If TZ is assigned, set the TZ value as the time zone - name: TZ value: America/New_York volumeMounts: - name: localtime mountPath: /etc/localtime readOnly: true - name: zoneinfo mountPath: /usr/share/zoneinfo readOnly: true resources: requests: cpu: 100m 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/v1kind: ClusterRolemetadata: name: kube-eventerrules: - apiGroups: - "" resources: - events verbs: - get - list - watch---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: annotations: name: kube-eventerroleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: kube-eventersubjects: - kind: ServiceAccount name: kube-eventer namespace: kube-system---apiVersion: v1kind: ServiceAccountmetadata: name: kube-eventer namespace: kube-system
支援下列通知程式釘釘阿里雲sls服務elasticsearch 服務honeycomb 服務influxdb 資料庫kafka 資料庫mysql 資料庫微信專案地址參考連結https://github.com/AliyunContainerService/kube-eventerhttps://github.com/AliyunContainerService/kube-eventer
最新評論