首页 > 其他分享 >67、K8S-部署管理-Helm部署Prometheus、TSDB数据持久化

67、K8S-部署管理-Helm部署Prometheus、TSDB数据持久化

时间:2023-04-15 10:56:03浏览次数:57  
标签:alertmanager monitoring 部署 67 Prometheus prom prometheus helm my

Kubernetes学习目录

1、准备仓库

1.1、配置prometheus仓库

1.1.1、增加prometheus仓库

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts

1.1.2、查询增加的结果

]# helm repo list
NAME                    URL                                               
bitnami                 https://charts.bitnami.com/bitnami                
prometheus-community    https://prometheus-community.github.io/helm-charts

1.2、查询prometheus

1.2.1、查询prometheus社区版

]# helm search repo prometheus-community
NAME                                                    CHART VERSION   APP VERSION     DESCRIPTION                                       
prometheus-community/alertmanager                       0.28.0          v0.25.0         The Alertmanager handles alerts sent by client ...
prometheus-community/alertmanager-snmp-notifier         0.1.0           v1.4.0          The SNMP Notifier handles alerts coming from Pr...
prometheus-community/jiralert                           1.2.0           v1.3.0          A Helm chart for Kubernetes to install jiralert   
prometheus-community/kube-prometheus-stack              45.9.1          v0.63.0         kube-prometheus-stack collects Kubernetes manif...
prometheus-community/kube-state-metrics                 5.4.0           2.8.2           Install kube-state-metrics to generate and expo...
prometheus-community/prom-label-proxy                   0.2.0           v0.6.0          A proxy that enforces a given label in a given ...
prometheus-community/prometheus                         20.2.0          v2.43.0         Prometheus is a monitoring system and time seri...
...

2、Helm部署Promtheus

mkdir /opt/helm_prometheus && cd /opt/helm_prometheus/

2.2、helm安装prometheus

2.2.1、拉取prometheus-community/prometheus

helm pull prometheus-community/prometheus

2.2.2、解压文件

tar xvf prometheus-20.2.0.tgz && cd prometheus/

2.2.3、prometheus将镜像地址修改为本地仓库

prometheus]# grep -E 'repository|tag' values.yaml | grep -v '^.*#'
      repository: 192.168.10.33:80/k8s/prometheus-operator/prometheus-config-reloader
      tag: v0.63.0
    repository: 192.168.10.33:80/k8s/prometheus/prometheus
    tag: "v2.41.0"

2.2.4、修改子charts将镜像地址修改为本地仓库

# 修改alertmanager
prometheus]# cat charts/alertmanager/values.yaml | grep -E 'image:|repository|tag' | grep -v '^.*#'
image:
  repository: 192.168.10.33:80/k8s/prometheus/alertmanager
  tag: "v0.25.0"
  image:
    repository: 192.168.10.33:80/k8s/configmap-reload
    tag: v0.8.0

# 修改kube-state-metrics
prometheus]# cat charts/kube-state-metrics/values.yaml | grep -E 'image:|repository|tag' | grep -v '^.*#'
image:
  repository: 192.168.10.33:80/kube-state-metrics/kube-state-metrics
  tag: "v2.7.0"
  image:
    repository: 192.168.10.33:80/k8s/brancz/kube-rbac-proxy
    tag: v0.14.0

# 修改node_exporter
prometheus]# cat charts/prometheus-node-exporter/values.yaml | grep -E 'image:|repository|tag' | grep -v '^.*#'
image:
  repository: 192.168.10.33:80/k8s/prometheus/node-exporter
  tag: "v1.5.0"

# 修改prometheus-pushgateway
prometheus]# cat charts/prometheus-pushgateway/values.yaml | grep -E 'image:|repository|tag' | grep -v '^.*#'
image:
  repository: 192.168.10.33:80/k8s/pushgateway
  tag: "latest"

2.2.5、关闭持久化存储

# 主要用于演示,生产的话,必须要配置上sc
# alertmanager关闭持久化存储 ]# vi charts/alertmanager/values.yaml persistence: enabled: true # prometheus关闭持久化存储 prometheus]# vi values.yaml # schedulerName: persistentVolume: ## If true, Prometheus server will create/use a Persistent Volume Claim ## If false, use emptyDir ## enabled: false

2.2.6、配置prometheus的ingress

prometheus]# vi values.yaml 
  ingress:
    enabled: true
    annotations:
      kubernetes.io/ingress.class: nginx
    hosts:
      - prom.localprom.com
    path: /
    pathType: Prefix

2.2.7、配置alertmanager的ingress

prometheus]# vi charts/alertmanager/values.yaml
ingress:
  enabled: true
  className: ""
  annotations:
    kubernetes.io/ingress.class: nginx
  hosts:
    - host: alert.localprom.com

2.3、开始使用heml部署

2.3.1、创建命名空间

kubectl create ns monitoring

2.3.2、打包安装

release_pkg]# helm package /opt/helm_prometheus/prometheus/
Successfully packaged chart and saved it to: /opt/helm_prometheus/release_pkg/prometheus-20.2.0.tgz

release_pkg]# helm install my-prom prometheus-20.2.0.tgz --namespace monitoring
NAME: my-prom
LAST DEPLOYED: Thu Apr 13 21:25:38 2023
NAMESPACE: monitoring
STATUS: deployed
REVISION: 1
NOTES:
The Prometheus server can be accessed via port 80 on the following DNS name from within your cluster:
my-prom-prometheus-server.monitoring.svc.cluster.local


Get the Prometheus server URL by running these commands in the same shell:
  export POD_NAME=$(kubectl get pods --namespace monitoring -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}")
  kubectl --namespace monitoring port-forward $POD_NAME 9090
#################################################################################
######   WARNING: Persistence is disabled!!! You will lose your data when   #####
######            the Server pod is terminated.                             #####
#################################################################################


The Prometheus alertmanager can be accessed via port  on the following DNS name from within your cluster:
my-prom-prometheus-%!s(<nil>).monitoring.svc.cluster.local


Get the Alertmanager URL by running these commands in the same shell:
  export POD_NAME=$(kubectl get pods --namespace monitoring -l "app=prometheus,component=" -o jsonpath="{.items[0].metadata.name}")
  kubectl --namespace monitoring port-forward $POD_NAME 9093
#################################################################################
######   WARNING: Persistence is disabled!!! You will lose your data when   #####
######            the AlertManager pod is terminated.                       #####
#################################################################################
#################################################################################
######   WARNING: Pod Security Policy has been disabled by default since    #####
######            it deprecated after k8s 1.25+. use                        #####
######            (index .Values "prometheus-node-exporter" "rbac"          #####
###### .          "pspEnabled") with (index .Values                         #####
######            "prometheus-node-exporter" "rbac" "pspAnnotations")       #####
######            in case you still need it.                                #####
#################################################################################


The Prometheus PushGateway can be accessed via port 9091 on the following DNS name from within your cluster:
my-prom-prometheus-pushgateway.monitoring.svc.cluster.local


Get the PushGateway URL by running these commands in the same shell:
  export POD_NAME=$(kubectl get pods --namespace monitoring -l "app=prometheus-pushgateway,component=pushgateway" -o jsonpath="{.items[0].metadata.name}")
  kubectl --namespace monitoring port-forward $POD_NAME 9091

For more information on running Prometheus, visit:
https://prometheus.io/

2.4、查询运行的状态

2.4.1、查询helm状态

]# helm -n monitoring list
NAME    NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                   APP VERSION
my-prom monitoring      1               2023-04-14 00:14:02.704314691 +0800 CST deployed        prometheus-20.2.0       v2.43.0 

2.4.2、查询运行pod状态

]# kubectl -n monitoring get pods -o wide
NAME                                             READY   STATUS    RESTARTS   AGE     IP              NODE      NOMINATED NODE   READINESS GATES
my-prom-alertmanager-0                           1/1     Running   0          3m48s   10.244.3.32     node1     <none>           <none>
my-prom-kube-state-metrics-578d99fccd-948jp      1/1     Running   0          3m48s   10.244.4.28     node2     <none>           <none>
my-prom-prometheus-node-exporter-fdzd9           1/1     Running   0          3m48s   192.168.10.26   master1   <none>           <none>
my-prom-prometheus-node-exporter-hmzv5           1/1     Running   0          3m48s   192.168.10.27   master2   <none>           <none>
my-prom-prometheus-node-exporter-pd4t8           1/1     Running   0          3m48s   192.168.10.29   node1     <none>           <none>
my-prom-prometheus-node-exporter-wbvr8           1/1     Running   0          3m48s   192.168.10.30   node2     <none>           <none>
my-prom-prometheus-pushgateway-d8f59f5cd-5czmf   1/1     Running   0          3m48s   10.244.4.27     node2     <none>           <none>
my-prom-prometheus-server-5f99d8b8c6-qkrjz       2/2     Running   0          3m48s   10.244.3.31     node1     <none>           <none>

2.4.3、查询ingress状态

]# kubectl -n monitoring get ingress
NAME                        CLASS    HOSTS                 ADDRESS         PORTS   AGE
my-prom-alertmanager        <none>   alert.localprom.com   192.168.10.29   80      4m18s
my-prom-prometheus-server   <none>   prom.localprom.com    192.168.10.29   80      4m18s

2.4.5、查询prometheus网页

2.4.6、查询alertmanager网页

 

3、Prometheus-persistentVolume-TSDB持久化问题解决

3.1、创建StorageClass资源

关于SC,请参考小节:https://www.cnblogs.com/ygbh/p/17319970.html

]# kubectl get sc
NAME     PROVISIONER                                   RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
nfs-sc   k8s-sigs.io/nfs-subdir-external-provisioner   Delete          Immediate           false                  75m

 

3.2、配置values.yaml

prometheus]# vi values.yaml 
server:
  ### The data directory used by prometheus to set --storage.tsdb.path
  ### 主要设置prometheus数据库保存的数据
  storagePath: "/data"
  
  persistentVolume:
    accessModes:
      - ReadWriteMany
    mountPath: /data
    size: 8Gi
    storageClass: "nfs-sc"

3.3、打包安装

helm package /opt/helm_prometheus/prometheus/
helm install my-prom prometheus-20.2.0.tgz -n monitoring

3.4、查询运行的状态

3.4.1、helm运行状态

helm_prometheus]# helm  list
NAME    NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                   APP VERSION
my-prom default         1               2023-04-15 00:21:09.252727402 +0800 CST deployed        prometheus-20.2.0       v2.43.0  

3.4.2、查询pod运行状态

helm_prometheus]# kubectl get pod -n monitoring 
NAME                                             READY   STATUS    RESTARTS   AGE
my-prom-alertmanager-0                           1/1     Running   0          8m10s
my-prom-kube-state-metrics-578d99fccd-x9m54      1/1     Running   0          8m10s
my-prom-prometheus-node-exporter-48m69           1/1     Running   0          8m10s
my-prom-prometheus-node-exporter-vbbcl           1/1     Running   0          8m10s
my-prom-prometheus-node-exporter-zmxzn           1/1     Running   0          8m10s
my-prom-prometheus-pushgateway-d8f59f5cd-krw9n   1/1     Running   0          8m10s
my-prom-prometheus-server-7cdb88d757-vbp7v       2/2     Running   0          8m10s

3.4.3、查询NFS目录数据

nfs-data]# tree 
.
├── alertmanager_data
├── lost+found
└── promtheus_data
    └── default-my-prom-prometheus-server-pvc-d46dd959-fa69-4d97-a47b-17b6fd1a2c5d
        ├── chunks_head
        ├── lock
        ├── queries.active
        └── wal
            └── 00000000

6 directories, 3 files

# 说明数据已经写入NFS挂载点

3.5、删除helm分析数据是否持久化

3.5.1、删除prometheus helm

helm_prometheus]# helm -n monitoring uninstall my-prom
release "my-prom" uninstalled

3.5.2、查询NFS数据还是存在

nfs-data]# tree 
.
├── alertmanager_data
├── lost+found
└── promtheus_data
    └── archived-monitoring-my-prom-prometheus-server-pvc-5faf5c4b-8493-4465-a9c0-2624f1096488
        ├── chunks_head
        ├── queries.active
        └── wal
            └── 00000000
# 数据还是存在

3.5.3、数据的删和留是由SC配置决定

我们当前StorageClass配置是如下:

archiveOnDelete: "ture"  
reclaimPolicy: Delete 

1、pod删除重建后数据依然存在,旧pod名称及数据依然保留给新pod使用
2、sc删除重建后数据依然存在,旧pod名称及数据依然保留给新pod使用
3、删除PVC后,PV不会别删除,且状态由Bound变为Released,NFS Server对应数据被保留
4、重建sc后,新建PVC会绑定新的pv,旧数据可以通过拷贝到新的PV中

可以参考小节-K8S-StorageClass资源-实践https://www.cnblogs.com/ygbh/p/17319970.html#_label4

 

标签:alertmanager,monitoring,部署,67,Prometheus,prom,prometheus,helm,my
From: https://www.cnblogs.com/ygbh/p/17316131.html

相关文章

  • 【230415-3】已知:在平行四边形ABCD中,AC=AB,过点D作DE垂直AC,分别较AB、AC与点E、F,若∠AB
    【题目】已知:在平行四边形ABCD中,AC=AB,过点D作DE垂直AC,分别较AB、AC与点E、F,若∠ABC=67.5°,过点E作EG垂直BC于G,连接EC、FG 求证:EF+FC=根号2倍FG......
  • windows 平台下单机部署nginx 实现api网关效果
    1下载windows版本的nginx链接:https://pan.baidu.com/s/1EPcqgLdcq7y96OcZ2LInuw提取码:0ris 2下载解压压缩包,不需安装1)解压压缩文件夹,进入nginx-1.20.2目录,然后在目录下打开cmd,启动命令startnginx2)查看nginx任务进程是否存在,命令tasklist/fi"imagenameeqn......
  • Docker中使用Nginx部署Web项目
    环境Ubuntu22.04.2LTSdocker安装官网教程Setup [Docker’spackagerepository](https://docs.docker.com/engine/install/ubuntu/#set-up-the-repository).只需要前三步,后面的步骤是安装DockerEngineDownloadlatest DEBpackage.Nginx使用镜像创建一个容器......
  • Maui安卓调试时部署报错:ADB1000
    突发情况,于是重新建了个项目,什么都没动的直接选择安卓仿真器。点击部署。于是等了半天,打开仿真器变慢了。部署也变慢了,CPU直接嗷嗷响,温度瞬间直飙80多度。接着仿真器是打开了,但一直都是黑屏。然后就是一个报错。报错内容: 错误ADB1000:System.IO.FileNotFoundException:......
  • docker_day04:Dockerfile docker私有仓库 dockercompose介绍 dockercompose部署 一件部
    目录回顾Dokerfile常用和不常用命令dockerfile构建一个djagno项目公司中,使用Docker开发的工作流程docker私有仓库镜像传到官方仓库镜像分层私有仓库搭建dockercompose介绍dockercompose部署flask+redis项目新建flask项目app.py编写Dockerfile--->>>用于构建flask项目的镜像编写......
  • 保姆级教你从零到一搭建服务器和部署个人网站(4)
    十、URL静态化1、网站伪静态设置紧接着上一节的内容(如果没有观看的话,请点击链接:保姆级教你从零到一搭建服务器和部署个人网站(3))登录进入宝塔面板,点击网站,打开域名后的设置,点击伪静态,在下拉框中选择wordpress2、URL链接静态化打开WordPress后台,在左侧选择设置中的固定链接,将URL路径......
  • ubuntu22.04 部署 dnsmasq
    禁用systemd-resolved#sudosystemctldisablesystemd-resolved#sudosystemctlstopsystemd-resolved安装依赖#apt-yinstallmakegcc下载dnsmasq#wgethttps://thekelleys.org.uk/dnsmasq/dnsmasq-2.89.tar.gz安装dnsmasq创建dnsmasq用户#groupadd-rdnsmasq......
  • docker03 容器操作 应用部署 迁移备份 dockerfile
    今日内容详细目录今日内容详细1容器操作2应用部署2.1mysql部署2.2redis部署2.3nginx部署3迁移与备份4Dockerfile1容器操作#启动容器 dockerstart容器id#停止容器 dockerstop容器id#文件拷贝 #容器的文件copy到宿主机上(不是在容器内执行)dockercp容......
  • 学习K8S 使用Operator部署管理Nginx
    创建一个KubernetesOperator部署nginx的大致过程如下:确定您要使用的OperatorSDK版本并安装它。使用OperatorSDK命令行创建新的Operator项目。定义CustomResourceDefinition(CRD),即将在Kubernetes中定义的自定义资源规范,以及该资源的状态和操作。例如,定义一个名为......
  • 自己项目用到的Nginx环境部署手册
    nginxsticky基于cookie的负载均衡googler开发的google-perftools优化Nginx管理,性能将会有一定程度的提升[/size]([/size][size=10.5pt;font-family:'Calibri',sans-serif;"lang="EN-US]64位[/size]操作系统请先安装libunwind库,32位操作系统不要安装。libunwind库为基于64......