一、helm部署Prometheus
在artifacthub上查找prometheus的helm部署包
在k8s集群添加Prometheus的repo仓库
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
拉取Prometheus压缩包
helm pull prometheus-community/prometheus
解压压缩包
tar -zxvf prometheus-26.0.1.tgz
修改prometheus目录下values.yaml,添加storageClass,如何创建nfs的storageClass,请参考这里:k8s使用nfs创建storageClass
vim prometheus/values.yaml
继续修改altermanager下的values.yaml
vim prometheus/charts/alertmanager/values.yaml
执行helm安装Prometheus,并创建prometheus命名空间
helm install prometheus prometheus/ --version 26.0.1 --namespace prometheus --create-namespace
此外方便外部对其访问,将prometheus-server的service改为NodePort类型
修改完毕后对Prometheus进行upgrade升级
helm upgrade prometheus prometheus -n prometheus
使用集群任意ip+NodePort暴露的端口访问
二、helm部署grafana
同样在hub上搜索grafana
添加仓库
helm repo add grafana https://grafana.github.io/helm-charts
搜索grafana
helm search repo grafana
拉取仓库部署包
helm pull grafana/grafana
解压压缩包
tar -zxvf grafana-8.8.2.tgz
修改values.yaml,service的类型设置为NodePort,便于外部对其访问
执行helm安装,并创建grafana命名空间
helm install grafana grafana --namespace grafana --create-namespace --version 8.8.2
web访问,用户名默认:admin,密码获取使用下面命令
kubectl get secret --namespace grafana grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
使用集群ip+NodePort暴露的端口访问,输入上面的密钥
三、配置grafana监控集群健康
添加数据源,由于grafana与prometheus在同一个集群内,可以使用service_name.namespace加上内部80端口访问 ,也可使用集群ip+NodePort访问
测试正常
导入dashboard
输入id,也可自行去https://grafana.com/找自己喜欢的dashboard