# https://github.com/resmoio/kubernetes-event-exporter
# helm chart 다운로드
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm pull bitnami/kubernetes-event-exporter --untar
# pod 배포 변경이 있을때 receiver 로 알림 처림 설정
# values.yaml
config:
logLevel: debug
logFormat: pretty
# 7초 이상 오래된 event 무시(설정안하면 기본5초)
maxEventAgeSeconds: 7
# `client-side throttling` 에러가 발생시
# `Burst` to roughly match your events per minute
# `QPS` to be 1/5 of the burst
kubeQPS: 100
kubeBurst: 500
receivers:
- name: "webhook-alerts"
webhook:
endpoint: "https://ysoftman.test"
headers:
X-API-KEY: "123"
User-Agent: kube-event-exporter 1.0
Content-Type: "application/json"
layout: # Optional, 커스텀하게 필드를 만들면 json body 로 요청된다.
to: "ysoftman"
message: |
이건 테스트 메시지입니다.
kind: "{{ .InvolvedObject.Kind }}"
createdAt: "{{ .GetTimestampMs }}"
details:
message: "{{ .Message }}"
reason: "{{ .Reason }}"
type: "{{ .Type }}"
count: "{{ .Count }}"
kind: "{{ .InvolvedObject.Kind }}"
name: "{{ .InvolvedObject.Name }}"
namespace: "{{ .Namespace }}"
component: "{{ .Source.Component }}"
host: "{{ .Source.Host }}"
labels: "{{ toJson .InvolvedObject.Labels}}"
route:
routes:
# argocd application 이벤트 무시
- drop:
- namespace: "^argocd.*"
- kind: "Application"
match:
- receiver: "webhook-alerts"
# match 조건은 기본적으로 AND 연산이므로, OR 조건을 구현하려면 여러 개의 match 블록을 사용
# - match:
# - kind: "Pod|Deployment|ReplicaSet"
# receiver: "webhook-alerts"
- match:
- reason: "BackOff"
receiver: "webhook-alerts"
- match:
- reason: "CrashLoopBackOff"
receiver: "webhook-alerts"
- match:
- reason: "Killing"
receiver: "webhook-alerts"
- match:
- reason: "Scheduled"
receiver: "webhook-alerts"
- match:
- reason: "Pulling"
receiver: "webhook-alerts"
- match:
- reason: "Created"
receiver: "webhook-alerts"
- match:
- reason: "Failed"
receiver: "webhook-alerts"
- match:
- reason: "FailedSync"
receiver: "webhook-alerts"
# 설치
helm install k8s-event-exporter . -n ysoftman --create-namespace
prometheus 의 kube_pod_xxx 메트릭들을 활용해서 alert-manager 나 grafana 로 알림을 보낼 수 있어 그런지 많이 사용되지는 않는것 같다.
다만 좀더 자세한 정보와 빠른 클러스터에서 동작하니 좀더 빠르게 이벤트 파악해서 알람을 보낼 수 있고, slack, es 같은 외부 전송 설정은 쉽게 할 수 있는것 같다.
배포 완료 알림이나 crash, error 알림등의 용도로는 괜찮아 보인다.
k8s event exporter > promtail > loki(로그 수집) > grafana 로도 사용한다.
promtail agent 가 로그를 수집해서 loki 에저장하고, grafana 에서 datasource 를 loki 로 해서 보는 방식이다.
promtail & loki : https://github.com/grafana/loki
grafana k8s event exporter dashbard: https://grafana.com/grafana/dashboards/17882-kubernetes-event-exporter/
참고로 promtail 은 deprecated 됐고 대신 alloy(https://github.com/grafana/alloy)이 있다.