一、Prometheus监控部署
1、下载部署文件
# 使用此链接下载后解压即可
wget https://github.com/prometheus-operator/kube-prometheus/archive/refs/heads/release-0.13.zip
2、根据k8s集群版本获取不同的kube-prometheus版本部署
https://github.com/prometheus-operator/kube-prometheus/tree/release-0.13
3、解压下载好的文件
unzip kube-prometheus-release-0.13.zip
kube-prometheus-release-0.13 # 解压后得到一个目录
4、在执行create前需要修改以下三个文件内容
prometheus-service.yaml
alertmanager-service.yaml
grafana-service.yaml
4.1、需要在service文件中添加type类型为NodePort
cat prometheus-service.yaml
apiVersion: v1
kind: Service
metadata:labels:app.kubernetes.io/component: prometheusapp.kubernetes.io/instance: k8sapp.kubernetes.io/name: prometheusapp.kubernetes.io/part-of: kube-prometheusapp.kubernetes.io/version: 2.46.0name: prometheus-k8snamespace: monitoring
spec:type: NodePort # 添加此行即可,grafana和alertmanager修改方式相同ports:- name: webport: 9090targetPort: web- name: reloader-webport: 8080targetPort: reloader-webselector:app.kubernetes.io/component: prometheusapp.kubernetes.io/instance: k8sapp.kubernetes.io/name: prometheusapp.kubernetes.io/part-of: kube-prometheussessionAffinity: ClientIP
5、进入kube-prometheus-release-0.13 目录
# 进入到 /root/kube-prometheus-release-0.13/manifests/setup 此目录执行创建命令
cd /root/kube-prometheus-release-0.13/manifests/setup # 此目录会创建自定义资源类型
kubectl create -f . # 使用.表示执行此目录下的所有文件
cd /root/kube-prometheus-release-0.13/manifests #此目录是创建prometheus和grafana的主要yaml文件目录
kubectl create -f . # 使用.表示执行此目录下的所有文件
6、查看pod运行状态
# 出现下面内容说明pod正常运行
kubectl get pod -n monitoring
NAME READY STATUS RESTARTS AGE
alertmanager-main-0 2/2 Running 0 41m
alertmanager-main-1 2/2 Running 0 41m
alertmanager-main-2 2/2 Running 0 41m
blackbox-exporter-6cfc4bffb6-wp2wm 3/3 Running 0 41m
grafana-748964b847-w4hht 1/1 Running 0 41m
kube-state-metrics-6b4d48dcb4-2cfmm 3/3 Running 0 41m
node-exporter-hb5ds 2/2 Running 2 (52m ago) 59m
node-exporter-zth9n 2/2 Running 0 59m
prometheus-adapter-79c588b474-njqtv 1/1 Running 0 43m
prometheus-adapter-79c588b474-r6z49 1/1 Running 0 43m
prometheus-k8s-0 2/2 Running 0 42m
prometheus-k8s-1 2/2 Running 0 42m
prometheus-operator-68f6c79f9d-m8wqq 2/2 Running 0 44m
7、查看svc信息
kubectl get svc -n monitoring
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
alertmanager-main ClusterIP 10.101.105.4 <none> 9093/TCP,8080/TCP 66m
alertmanager-operated ClusterIP None <none> 9093/TCP,9094/TCP,9094/UDP 64m
blackbox-exporter ClusterIP 10.101.98.31 <none> 9115/TCP,19115/TCP 66m
grafana NodePort 10.106.85.113 <none> 3000:32537/TCP 66m
kube-state-metrics ClusterIP None <none> 8443/TCP,9443/TCP 66m
node-exporter ClusterIP None <none> 9100/TCP 66m
prometheus-adapter ClusterIP 10.109.49.125 <none> 443/TCP 66m
prometheus-k8s NodePort 10.98.19.241 <none> 9090:32326/TCP,8080:30435/TCP 66m
prometheus-operated ClusterIP None <none> 9090/TCP 64m
prometheus-operator ClusterIP None <none> 8443/TCP 66m
8、至此kube-prometheus监控部署完成
9、使用NodePort方式登录prometheus控制台查看监控节点是否正常
说明:里面都为up说明监控正常
10、使用grafana图形化展示
10.1、grafana初始账号密码为 admin/admin
10.2、添加数据源(此处数据源为prometheus)
10.3、选择数据源为prometheus
10.4、填写数据源名称和地址
10.5、填写完下拉进行测试
11、添加模版
12、grafana图形化展示如下
模板编号 15661
模板编号1860