Kubernetes Events事件收集与监控实战
创始人
2025-07-13 02:11:31
0

背景概述

大家好,我是安若,前两天群里的小伙伴问到Kubernetes的Event事件收集、监控告警该如何进行,那么这次就乘此机会分享一下当前使用的方案。

成品展示

本次仅分享events展示,并没有涉及到告警相关的,等下次有机会了再次分享一下吧。

图片图片

image

图片图片

image

图片图片

这里的词云没有展示出来,因为需要安装插件,可自行进行安装配置。

实战案例

环境说明

图片图片

Exporter部署

[root@192 deploy]# cat 00-roles.yaml  
apiVersion: v1
kind: Namespace
metadata:
  name: kube-ops
---
apiVersion: v1
kind: ServiceAccount
metadata:
  namespace: kube-ops
  name: event-exporter
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: event-exporter
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: view
subjects:
  - kind: ServiceAccount
    namespace: kube-ops
    name: event-exporter
[root@192 deploy]# cat 02-deployment.yaml  
apiVersion: apps/v1
kind: Deployment
metadata:
  name: event-exporter
  namespace: kube-ops
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: event-exporter
        version: v1
    spec:
      serviceAccountName: event-exporter
      containers:
        - name: event-exporter
          image: m.daocloud.io/ghcr.io/opsgenie/kubernetes-event-exporter:v0.11
          imagePullPolicy: IfNotPresent
          args:
            - -cnotallow=/data/config.yaml
          volumeMounts:
            - mountPath: /data
              name: cfg
      volumes:
        - name: cfg
          configMap:
            name: event-exporter-cfg
  selector:
    matchLabels:
      app: event-exporter
      version: v1

执行以上yaml文件,这里就直接略过了。不会自行百度。

Elasticsearch部署

  • 下载elasticsearch压缩包
# wget  https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.10.4-linux-x86_64.tar.gz
  • 解压
### 创建存放包的文件夹
# mkdir /data/soft -p

# tar -xvf elasticsearch-8.10.4-linux-x86_64.tar.gz  -C /data/soft/
  • 修改配置文件 config/elasticsearch.yml
cluster.name: my-elk
node.name: node-1
path.data: /data/soft/elasticsearch-8.10.4/data
path.logs: /data/soft/elasticsearch-8.10.4/logs
network.host: 0.0.0.0
http.port: 9200
  • 修改系统配置
# cat >> /etc/security/limits.conf <>  /etc/sysctl.conf <
  • 创建启动用户
# useradd es
  • 修改文件权限
#  chown es:es elasticsearch-8.10.4/ -R
  • 创建systemctl启动配置
# /etc/systemd/system/elasticsearch.service
[Unit]
Descriptinotallow=Elasticsearch
Documentatinotallow=https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html

[Service]
User=es
ExecStart=/data/soft/elasticsearch-8.10.4/bin/elasticsearch
TimeoutStopSec=20
Restart=always
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target

关于如何reload、启动这里就直接略过了哦。不会自行百度。

重置elasticsearch密码

# ./elasticsearch-reset-password -u elastic  
This tool will reset the password of the [elastic] user to an autogenerated value.
The password will be printed in the console.
Please confirm that you would like to continue [y/N]y


Password for the [elastic] user successfully reset.
New value: l5tL-0v74o15RlMzVkY

当我们为elastic用户重置密码时,输入确定后,即可生成一个新的密码,这里的密码为:l5tL-0v74o15RlMzVkY

Grafana部署

  • 下载Grafana压缩包
wget  https://dl.grafana.com/enterprise/release/grafana-enterprise-9.4.2.linux-amd64.tar.gz
  • 解压
tar -xvf    grafana-enterprise-9.4.2.linux-amd64.tar.gz   -C   /data/soft
  • 启动
nohup ./grafana-server  >/dev/null 2>&1 &

我这里直接使用的nohup启动,当然你也可以在kubernetes、docker中部署等等。

Grafana连接Elastic

图片图片

其中这里的ca是elasitc中的,具体路径为config/certs/http_ca.crt ,这里的Password为我们重置后的es密码。

图片图片

图片图片

这里就不做过多的解释了。不明白的,加群问吧。

导入dashboard

图片图片

总结

到此我们关于events的展示基本上已经完结了,至于告警的分享等时间允许了会再次分享。

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
各种千兆交换机的数据接口类型详... 千兆交换机有很多值得学习的地方,这里我们主要介绍各种千兆交换机的数据接口类型,作为局域网的主要连接设...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
Windows恶意软件20年“... 在Windows的早期年代,病毒游走于系统之间,偶尔删除文件(但被删除的文件几乎都是可恢复的),并弹...
规避非法攻击 用好路由器远程管... 单位在市区不同位置设立了科技服务点,每一个服务点的员工都通过宽带路由器进行共享上网,和单位网络保持联...
范例解读VB.NET获取环境变... VB.NET编程语言的使用范围非常广泛,可以帮助开发人员处理各种程序中的需求,而且还能对移动设备进行...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...