美文网首页linux运维
k8s部署-53-使用helm3部署监控prometheus(普

k8s部署-53-使用helm3部署监控prometheus(普

作者: 运维家 | 来源:发表于2022-05-05 21:13 被阅读0次

本文将带你从头到尾的来实现如何在k8s中部署一整套Prometheus监控系统,以及有哪些部署方式可以选择,让你轻松掌握。

1、Prometheus(普罗米修斯)部署方式

(1)手动部署

(2)Helm

  • 类似于centos中的yum命令,是k8s中的包管理工具
  • 一个包一个Chart(一个目录)

(3)Prometheus Operator

(4)Helm + Prometheus Operator

  • 我们这里采用这种方式来部署Prometheus监控

2、k8s的Helm安装

版本我们选择最新的功能版本:3.8.0

下载地址可以从我微信公众号(运维家)后台回复:helm,即可获取下载地址。

上传到指定目录进行如下操作;

# 解压
[root@node1 ~]# tar xf helm-v3.8.0-linux-amd64.tar.gz 
# 移动到bin目录下
[root@node1 ~]# mv linux-amd64/helm /usr/local/bin/helm
# 环境变量根据个人情况进行配置如下
[root@node1 ~]# echo "export PATH=$PATH:/usr/local/bin/" >> /etc/profile
[root@node1 ~]# helm version
version.BuildInfo{Version:"v3.8.0", GitCommit:"d14138609b01886f544b2025f5000351c9eb092e", GitTreeState:"clean", GoVersion:"go1.17.5"}
[root@node1 ~]# 

3、安装Prometheus

由于helm默认会访问外网,有可能网速比较慢,那么我们采用直接把charts下载到本地的方式来安装;

(1)从github上下载整个charts

地址如下:

https://github.com/helm/charts

登录之后复制git下载地址;

https://github.com/helm/charts.git

之后在我们的master节点上,使用如下命令进行下载;

[root@node1 ~]# git clone https://github.com/helm/charts.git

如果说上一步git clone执行失败的话,可以从微信公众号(运维家)后台回复:charts,即可获取软件包,解压即可使用;

unzip charts-master.zip

(2)安装Prometheus

查看charts中的prometheus

[root@node1 ~]# ls charts-master/stable/prometheus-operator/
Chart.yaml  ci  CONTRIBUTING.md  crds  hack  README.md  requirements.lock  requirements.yaml  templates  values.yaml
[root@node1 ~]# 

安装;

# 复制程序包
[root@node1 ~]# cp -ra charts-master/stable/prometheus-operator .
# 创建存放依赖的目录
[root@node1 ~]# mkdir prometheus-operator/charts
# 复制依赖
[root@node1 ~]# cp -ra charts-master/stable/kube-state-metrics/ prometheus-operator/charts/
[root@node1 ~]# cp -ra charts-master/stable/prometheus-node-exporter/ prometheus-operator/charts/
[root@node1 ~]# cp -ra charts-master/stable/grafana/ prometheus-operator/charts/
# 安装,并命名为 monitor,这样子方便查找
[root@node1 ~]# helm install monitor ./prometheus-operator/

出现如下信息就表示安装成功了;

NOTES:
*******************
*** DEPRECATED ****
*******************
* stable/prometheus-operator chart is deprecated.
* Further development has moved to https://github.com/prometheus-community/helm-charts
* The chart has been renamed kube-prometheus-stack to more clearly reflect
* that it installs the `kube-prometheus` project stack, within which Prometheus
* Operator is only one component.

The Prometheus Operator has been installed. Check its status by running:
  kubectl --namespace default get pods -l "release=monitor"

Visit https://github.com/coreos/prometheus-operator for instructions on how
to create & configure Alertmanager and Prometheus instances using the Operator.
[root@node1 ~]#

但是需要注意的是,安装成功只是表明相关配置做好了,我们还需要实际运行下上面的命令来检查下状态的;

[root@node1 ~]# kubectl --namespace default get pods -l "release=monitor"
NAME                                                   READY   STATUS              RESTARTS   AGE
monitor-prometheus-node-exporter-9pdwj                 0/1     ContainerCreating   0          3m48s
monitor-prometheus-node-exporter-v9qhp                 1/1     Running             0          3m48s
monitor-prometheus-operato-operator-79458977df-5jgkb   0/2     ContainerCreating   0          3m48s
[root@node1 ~]# 
[root@node1 ~]# kubectl get all 
NAME                                                         READY   STATUS              RESTARTS   AGE
pod/alertmanager-monitor-prometheus-operato-alertmanager-0   0/2     ContainerCreating   0          47s
pod/monitor-grafana-775969b799-6tldl                         0/2     PodInitializing     0          8m42s
pod/monitor-kube-state-metrics-574788cc57-r9gtf              0/1     ImagePullBackOff    0          8m42s
pod/monitor-prometheus-node-exporter-9pdwj                   1/1     Running             0          8m42s
pod/monitor-prometheus-node-exporter-v9qhp                   1/1     Running             0          8m42s
pod/monitor-prometheus-operato-operator-79458977df-5jgkb     0/2     ContainerCreating   0          8m42s
pod/prometheus-monitor-prometheus-operato-prometheus-0       0/3     ContainerCreating   0          37s

NAME                                              TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
service/alertmanager-operated                     ClusterIP   None             <none>        9093/TCP,9094/TCP,9094/UDP   48s
service/kubernetes                                ClusterIP   10.233.0.1       <none>        443/TCP                      6d19h
service/monitor-grafana                           ClusterIP   10.233.10.12     <none>        80/TCP                       8m44s
service/monitor-kube-state-metrics                ClusterIP   10.233.199.229   <none>        8080/TCP                     8m44s
service/monitor-prometheus-node-exporter          ClusterIP   10.233.69.10     <none>        9100/TCP                     8m44s
service/monitor-prometheus-operato-alertmanager   ClusterIP   10.233.51.110    <none>        9093/TCP                     8m44s
service/monitor-prometheus-operato-operator       ClusterIP   10.233.209.238   <none>        8080/TCP,443/TCP             8m44s
service/monitor-prometheus-operato-prometheus     ClusterIP   10.233.40.187    <none>        9090/TCP                     8m44s
service/prometheus-operated                       ClusterIP   None             <none>        9090/TCP                     38s
service/springboot-web-demo                       ClusterIP   10.233.16.229    <none>        80/TCP                       5d19h
service/springboot-web-svc                        ClusterIP   None             <none>        80/TCP                       6d19h

NAME                                              DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
daemonset.apps/monitor-prometheus-node-exporter   2         2         2       2            2           <none>          8m44s

NAME                                                  READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/monitor-grafana                       0/1     1            0           8m44s
deployment.apps/monitor-kube-state-metrics            0/1     1            0           8m44s
deployment.apps/monitor-prometheus-operato-operator   0/1     1            0           8m44s

NAME                                                             DESIRED   CURRENT   READY   AGE
replicaset.apps/monitor-grafana-775969b799                       1         1         0       8m43s
replicaset.apps/monitor-kube-state-metrics-574788cc57            1         1         0       8m43s
replicaset.apps/monitor-prometheus-operato-operator-79458977df   1         1         0       8m43s

NAME                                                                    READY   AGE
statefulset.apps/alertmanager-monitor-prometheus-operato-alertmanager   0/1     48s
statefulset.apps/prometheus-monitor-prometheus-operato-prometheus       0/1     38s
[root@node1 ~]# 

可以看到状态还是不对的,等待状态正常即可;

(3)长时间处于ContainerCreating状态;

在我这边的时候,有两个pod无法正常运行,分别是alertmanager-monitor-prometheus-operato-alertmanagerprometheus-monitor-prometheus-operato-prometheus,主要原因就是第一个pod的镜像无法下载,这个时候我们可以改一下这个镜像的下载地址,然后在更新一下;

更新alertmanager-monitor-prometheus-operato-alertmanager镜像地址;

[root@node1 ~]# cd prometheus-operator/
[root@node1 prometheus-operator]# vim values.yaml 
[root@node1 prometheus-operator]# 
# 原信息
image:
  repository: quay.io/prometheus/alertmanager
  tag: v0.21.0
  sha: ""
# 改成如下信息
image:
  repository: registry.cn-beijing.aliyuncs.com/yunweijia0909/alertmanager
  tag: v0.21.0
  sha: ""
[root@node1 prometheus-operator]# helm upgrade monitor -f values.yaml ../prometheus-operator/
# 或者采用如下方式,直接来修改这个pod的images地址,也可以
[root@node1 ~]# kubectl edit pod alertmanager-monitor-prometheus-operato-alertmanager-0
# 地址修改如下:
image: registry.cn-beijing.aliyuncs.com/yunweijia0909/alertmanager:v0.21.0

更新prometheus-monitor-prometheus-operato-prometheus,这里在上一步操作完毕之后,他就自动成功了;

最后状态如下:

[root@node1 ~]# kubectl get pod
NAME                                                     READY   STATUS    RESTARTS   AGE
alertmanager-monitor-prometheus-operato-alertmanager-0   2/2     Running   0          26m
monitor-grafana-775969b799-6tldl                         2/2     Running   2          3h26m
monitor-kube-state-metrics-574788cc57-r9gtf              1/1     Running   1          3h26m
monitor-prometheus-node-exporter-9pdwj                   1/1     Running   1          3h26m
monitor-prometheus-node-exporter-v9qhp                   1/1     Running   1          3h26m
monitor-prometheus-operato-operator-79458977df-5jgkb     2/2     Running   2          3h26m
prometheus-monitor-prometheus-operato-prometheus-0       3/3     Running   1          3h18m
[root@node1 ~]#

4、访问Prometheus(普罗米修斯)

剩余内容请转至VX公众号 “运维家” ,回复 “159” 查看。

------ 以下内容为防伪内容,忽略即可 ------

------ 以下内容为防伪内容,忽略即可 ------

------ 以下内容为防伪内容,忽略即可 ------

linux配置网关,linux查看进程占用,linux磁盘方案,linux如何更改权限,怎么对linux文件杀毒,linux应用安装在哪个目录,linux启用otp,linux杀毒工作站,linux查看虚ip,linux获取挂载点命令,linuxqt监测进程,linux系统dd到优盘,linuxr语言内存,linux显卡2070花屏,网络检测工具linux,linux查看raid模式,linux中c编程,linux安装蚂蚁森林脚本,linux可以玩吃鸡吗,linux删除引导重装系统。

相关文章

网友评论

    本文标题:k8s部署-53-使用helm3部署监控prometheus(普

    本文链接:https://www.haomeiwen.com/subject/somoyrtx.html