k8s event exporter

# k8s event exporter 로 k8 에서 발생하는 이벤트들을 체크하여 알림을 보낼 수 있다.
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 }}"
              name: "{{ .InvolvedObject.Name }}"
              namespace: "{{ .Namespace }}"
              component: "{{ .Source.Component }}"
              host: "{{ .Source.Host }}"
              labels: "{{ toJson .InvolvedObject.Labels}}"
  route:
    routes:
      # match 조건은 기본적으로 AND 연산이므로, OR 조건을 구현하려면 여러 개의 match 블록을 사용
      # - match:
      #     - kind: "Pod|Deployment|ReplicaSet"
      #       receiver: "webhook-alerts"
      - match:
          - type: "Warning"
            receiver: "webhook-alerts"

      - match:
          - reason: "FailedSync"
            receiver: "webhook-alerts"

# 설치
helm install k8s-event-exporter . -n ysoftman --create-namespace

# 다음과 같이 없는 이미지로 pod 를 생성시도하면 Warning 이벤트가 발생해서 위 알람 설정이 동작하는지 확인 할 수 있다.
kubectl create ns test-warn
kubectl run badimage --image=nonexistentrepo/nonimage:latest --restart=Never -n test-warn

# 참고
prometheus 의 kube-state-metrics(container)등이 생성하는 메트릭들을 활용해서 alert-manager 나 grafana 로 알림을 보낼 수 있어 그런지 많이 사용되지는 않는것 같다.
그래도 장점을 생각해보면
- 기본 1시간이 지나면 사라지는 이벤트 정보를 외부로 보내 저장할 수 있다.
- prometheus 메트릭으로 수집되지 않는 이벤트를 파악할 수 있다.
- 클러스터에서 동작하니 좀더 빠르게 이벤트 파악해서 알람을 보낼 수 있다. 
- slack, es 같은 외부 전송 설정을 비교적 쉽게할 수 있다.
배포 완료, 메트릭이 수집 안되는 노드 장애등의 에러 알림 등의 용도로는 괜찮아 보인다.

k8s event exporter > loki(로그 수집) > grafana 로도 사용한다.

comments:

댓글 쓰기