惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
H
Help Net Security
N
Netflix TechBlog - Medium
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
A
About on SuperTechFans
V
V2EX
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
宝玉的分享
宝玉的分享
aimingoo的专栏
aimingoo的专栏
F
Fortinet All Blogs
博客园 - 【当耐特】
Microsoft Security Blog
Microsoft Security Blog
Martin Fowler
Martin Fowler
I
InfoQ
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
Engineering at Meta
Engineering at Meta
腾讯CDC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
U
Unit 42
The Cloudflare Blog
Y
Y Combinator Blog

二丫讲梵

学习周刊-总第258期-2026年第15周 学习周刊-总第257期-2026年第14周 学习周刊-总第256期-2026年第13周 学习周刊-总第255期-2026年第12周 学习周刊-总第254期-2026年第11周 学习周刊-总第253期-2026年第10周 临时插播一条羊毛,免费领取450元大模型API代金券 学习周刊-总第252期-2026年第09周 学习周刊-总第251期-2026年第08周 学习周刊-总第250期-2026年第07周 学习周刊-总第249期-2026年第06周 诚邀评论,聊聊你所知欲知的我 学习周刊-总第248期-2026年第05周 我的QQ动态之2015年 我的QQ动态之2014年 我的QQ动态之2013年 我的QQ动态之2012年 我的QQ动态-2010-2011年 我的QQ动态-创栏小叙 学习周刊-总第247期-2026年第04周 Nexus社区版权益阉割--一文告诉你有哪些版本可以选择 学习周刊-总第246期-2026年第03周 学习周刊-总第245期-2026年第02周 学习周刊-总第244期-2026年第01周 学习周刊-总第243期-2025年第52周 学习周刊-总第242期-2025年第51周 开源项目ZenOps:带你领略禅意运维 学习周刊-总第241期-2025年第50周 用京东金融,享负债人生 学习周刊-总第240期-2025年第49周
AWS运维部署实践--EKS集群事件采集
二丫讲梵 · 2024-12-09 · via 二丫讲梵

默认情况下,k8s 集群的事件会保留一个小时,当你在遇到容器异常重启,想要追溯更早的事件时,会发现已经看不到了,因此集群事件的导出并采集也是集群管理的一个基本事项。

在开源社区也有一些项目集成了这个能力,本文介绍其中一种。

项目地址: kubernetes-event-exporter (opens new window)

将事件输出到标准输出以便于观察与调试:

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: event-exporter
  namespace: monitor
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: event-exporter
rules:
  - apiGroups: ["*"]
    resources: ["*"]
    verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: event-exporter
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: event-exporter
subjects:
  - kind: ServiceAccount
    name: event-exporter
    namespace: monitor
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: event-exporter-config
  namespace: monitor
data:
  config.yaml: |
    logLevel: debug
    logFormat: json
    clusterName: "aws3-sgp-eks-cluster"
    route:
      routes:
        - match:
            - receiver: "stdout"
    receivers:
      - name: "stdout"
        stdout: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: event-exporter
  namespace: monitor
spec:
  replicas: 1
  selector:
    matchLabels:
      app: event-exporter
  template:
    metadata:
      labels:
        app: event-exporter
    spec:
      serviceAccountName: event-exporter
      containers:
        - name: event-exporter
          image: registry.cn-hangzhou.aliyuncs.com/opsre/kubernetes-event-exporter
          args:
            - "-conf=/config/config.yaml"
          volumeMounts:
            - name: config-volume
              mountPath: /config
      volumes:
        - name: config-volume
          configMap:
            name: event-exporter-config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

同时也支持将日志导出到 kafka,只需要替换其中的 configmap 即可:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: event-exporter-config
  namespace: monitor
data:
  config.yaml: |
    logLevel: warn
    logFormat: json
    clusterName: aws3-sgp-eks-cluster
    route:
      routes:
        - match:
            - receiver: "kafka"
    receivers:
    - name: "kafka"
      kafka:
        clientId: "aws3-sgp-eks-cluster"
        topic: "eks_event_log"
        brokers:
          - "10.0.0.1:9092"
        compressionCodec: "snappy"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

同时该工具还支持对事件内容的预处理,比如你可能只关心如下几个字段:

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: event-exporter-config
  namespace: monitor
data:
  config.yaml: |
    logLevel: warn
    logFormat: json
    clusterName: aws3-sgp-eks-cluster
    route:
      routes:
        - match:
            - receiver: "kafka"
    receivers:
    - name: "kafka"
      kafka:
        clientId: "aws3-sgp-eks-cluster"
        topic: "eks_event_log"
        brokers:
          - "10.0.0.1:9092"
        compressionCodec: "snappy"
        layout: #optional
          kind: "{{ .InvolvedObject.Kind }}"
          namespace: "{{ .InvolvedObject.Namespace }}"
          name: "{{ .InvolvedObject.Name }}"
          reason: "{{ .Reason }}"
          message: "{{ .Message }}"
          type: "{{ .Type }}"
          createdAt: "{{ .GetTimestampISO8601 }}"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

这样输出的内容就只会有这几个字段,如果你还需要其他字段,可根据 stdout 调试的输出自行配置。