本文主要是介绍Kubernetes从0到1-第五篇 部署Prometheus监控,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
- 环境要求
- 安装
- 下载chart
- 修改父values.yaml
- 安装prometheus-operator
环境要求
- helm 版本 v3.3+
- kubernetes 集群版本 1.14+
- 添加国内chart仓库
首先,添加国内的镜像仓库源
helm repo add apphub https://apphub.aliyuncs.com
helm repo update
查看已经添加的 chart 库
helm repo list
- 创建命名空间 namespace
将 Prometheus 安装到独立的命名空间。
创建 namespace 的配置文件 monitoring.yaml
apiVersion: v1
kind: Namespace
metadata:name: monitoringlabels:name: monitoring
应用刚创建的 yaml 文件
kubectl apply -f monitoring.yaml
- 选择 prometheus-operator 版本
查询所需要的版本:
# helm search prometheus-operator -lapphub/prometheus-operator 8.7.0 0.35.0 Provides easy monitoring definitions for Kubernetes servi...
apphub/prometheus-operator 8.2.2 0.34.0 Provides easy monitoring definitions for Kubernetes servi...
apphub/prometheus-operator 8.2.0 0.34.0 Provides easy monitoring definitions for Kubernetes servi...
apphub/prometheus-operator 8.1.2 0.34.0 Provides easy monitoring definitions for Kubernetes servi...
apphub/prometheus-operator 7.1.1 0.32.0 Provides easy monitoring definitions for Kubernetes servi...
选择8.2.2版本安装。
安装
下载chart
helm pull apphub/prometheus-operator --version 8.2.2
tar -xvf prometheus-operator-8.2.2.tgz && cd prometheus-operator/
修改父values.yaml
alertmanager:ingress:enabled: truehosts: - alertmanager.demo.comservice:loadBalancerSourceRanges: ["192.168.238.0/24"]type: LoadBalancer
grafana:# 覆盖子chart(grafana)镜像版本image:repository: grafana/grafanatag: 8.1.0enabled: true# 启用密码adminPassword: admin@123456ingress:enabled: truehosts:- grafana.demo.comgrafana.ini:## 添加数据库信息,数据库配置信息将写入grafana配置文件 grafana.ini 中。database:type: mysqlhost: 192.168.238.150name: grafanauser: grafanapassword: ZdZ5GIBhssl_mode: disable
prometheus:enabled: trueservice:loadBalancerSourceRanges: ["192.168.238.0/24"]type: LoadBalanceringress:enabled: truehosts:- prometheus.demo.comprometheusSpec:# 持久化存储,实现TSDB数据持久化storageSpec: volumeClaimTemplate:spec:storageClassName: managed-nfs-storageaccessModes: ["ReadWriteOnce"]resources:requests:storage: 20Gi
安装prometheus-operator
helm install prometheus -n monitoring . -f ./values.yaml
查看运行的pod
kubectl get pods -n monitoringNAME READY STATUS RESTARTS AGE
alertmanager-prometheus-prometheus-oper-alertmanager-0 2/2 Running 0 4h2m
prometheus-grafana-b876dcf9c-9d92n 2/2 Running 0 4h2m
prometheus-kube-state-metrics-6f569f64f6-x2fxl 1/1 Running 0 4h2m
prometheus-prometheus-node-exporter-4bnd2 1/1 Running 0 4h2m
prometheus-prometheus-node-exporter-4j8m9 1/1 Running 0 4h2m
prometheus-prometheus-node-exporter-5md8v 1/1 Running 0 4h2m
prometheus-prometheus-oper-operator-7687488465-cmg9l 2/2 Running 0 4h2m
prometheus-prometheus-prometheus-oper-prometheus-0 3/3 Running 1 4h1m
查看ingress
kubectl get ingress -n monitoringNAME CLASS HOSTS ADDRESS PORTS AGE
prometheus-grafana <none> grafana.demo.com 192.168.238.156 80 20h
prometheus-prometheus-oper-alertmanager <none> alertmanager.demo.com 192.168.238.156 80 20h
prometheus-prometheus-oper-prometheus <none> prometheus.demo.com 192.168.238.156 80 20h
访问grafana
访问prometheus
访问alertmanager
参考文档
[1]: https://github.com/helm/charts/blob/master/stable/prometheus-operator/README.md
这篇关于Kubernetes从0到1-第五篇 部署Prometheus监控的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!