背景概述
大家好,我是安若,前两天群里的小伙伴问到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 <<EOF es hard nofile 65535 es soft nofile 65535 es nproc 4096 es hard memlock unlimited es soft memlock unlimited EOF # cat >> /etc/sysctl.conf <<EOF vm.swappiness=1 vm.max_map_count=262144 EOF ### 使其生效 # sysctl --system # su - root
- 创建启动用户
# 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的展示基本上已经完结了,至于告警的分享等时间允许了会再次分享。
原文地址:https://mp.weixin.qq.com/s/d4PhqhW8wp4bnr_Ft1hq9g