Kubernetes Events事件收集與監(jiān)控實戰(zhàn)
背景概述
大家好,我是安若,前兩天群里的小伙伴問到Kubernetes的Event事件收集、監(jiān)控告警該如何進(jìn)行,那么這次就乘此機(jī)會分享一下當(dāng)前使用的方案。
成品展示
本次僅分享events展示,并沒有涉及到告警相關(guān)的,等下次有機(jī)會了再次分享一下吧。
圖片
image
圖片
image
圖片
這里的詞云沒有展示出來,因為需要安裝插件,可自行進(jìn)行安裝配置。
實戰(zhàn)案例
環(huán)境說明
圖片
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
執(zhí)行以上yaml文件,這里就直接略過了。不會自行百度。
Elasticsearch部署
- 下載elasticsearch壓縮包
# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.10.4-linux-x86_64.tar.gz
- 解壓
### 創(chuàng)建存放包的文件夾
# 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
- 修改系統(tǒng)配置
# 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
- 創(chuàng)建啟動用戶
# useradd es
- 修改文件權(quán)限
# chown es:es elasticsearch-8.10.4/ -R
- 創(chuàng)建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
關(guān)于如何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
當(dāng)我們?yōu)閑lastic用戶重置密碼時,輸入確定后,即可生成一個新的密碼,這里的密碼為: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啟動,當(dāng)然你也可以在kubernetes、docker中部署等等。
Grafana連接Elastic
圖片
其中這里的ca是elasitc中的,具體路徑為config/certs/http_ca.crt ,這里的Password為我們重置后的es密碼。
圖片
圖片
這里就不做過多的解釋了。不明白的,加群問吧。
導(dǎo)入dashboard
圖片
總結(jié)
到此我們關(guān)于events的展示基本上已經(jīng)完結(jié)了,至于告警的分享等時間允許了會再次分享。