K8S 部署peometheus + grafana 监控

安装说明

如果有下载不下来的docker镜像可以私信我免费下载。
系统版本为 Centos7.9
内核版本为 6.3.5-1.el7
K8S版本为 v1.26.14
动态存储:部署文档
GitHub地址

下载yaml 文件

## 因为我的K8S 版本比较新,我下载的是当前的最新版本,你的要是老版本K8集群最好看一下那个版本是支持你的集群的。
git clone -b release-0.13 https://github.com/prometheus-operator/kube-prometheus.git

安装operator

cd ./kube-prometheus-release-0.13/manifests/setup
kubectl create -f ./cd /root/kube-prometheus-release-0.13/manifests
kubectl create -f ./

注意事项

默认的 yaml 文件里面有网络隔离配置,配置文件名字如下

[root@master01 manifests]#ls *networkPolicy.yaml
alertmanager-networkPolicy.yaml      grafana-networkPolicy.yaml           nodeExporter-networkPolicy.yaml       prometheus-networkPolicy.yaml
blackboxExporter-networkPolicy.yaml  kubeStateMetrics-networkPolicy.yaml  prometheusAdapter-networkPolicy.yaml  prometheusOperator-networkPolicy.yaml

正常按照默认的部署是不能访问这个监控的,需要修改配置,
举例:以 grafana-networkPolicy.yaml 配置文件为例(ingress-nginx 方式暴露服务,所以添加ingress-nginx 命名空间的pod允许访问Grafana即可。)

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:labels:app.kubernetes.io/component: grafanaapp.kubernetes.io/name: grafanaapp.kubernetes.io/part-of: kube-prometheusapp.kubernetes.io/version: 11.1.0name: grafananamespace: monitoring
spec:egress:- {}ingress:- from:- podSelector:matchLabels:app.kubernetes.io/name: prometheus- namespaceSelector: ## 添加允许访问策略matchLabels:name: ingress-nginxports:- port: 3000protocol: TCPpodSelector:matchLabels:app.kubernetes.io/component: grafanaapp.kubernetes.io/name: grafanaapp.kubernetes.io/part-of: kube-prometheuspolicyTypes:- Egress- Ingress

保存后重新部署,其他的网络隔离也是这样修改,此处不再一一举例。

kubectl replace -f grafana-networkPolicy.yaml

或者嫌麻烦可以直接删除 所有 networkPolicy

## 谨慎使用,当前命令会删除指定命名空间中所有networkPolicy 配置。
kubectl delete netpol -n monitoring --all

修改 prometheus-prometheus.yaml 文件

默认这个是没有持久化存储的并且prometheus 监控数据只能保存24小时,下面这个是我修改过的,修改监控数据保存时间,添加动态存储。

apiVersion: monitoring.coreos.com/v1
kind: Prometheus
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: k8snamespace: monitoring
spec:alerting:alertmanagers:- apiVersion: v2name: alertmanager-mainnamespace: monitoringport: webenableFeatures: []externalLabels: {}image: quay.io/prometheus/prometheus:v2.46.0nodeSelector:kubernetes.io/os: linuxpodMetadata: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.0podMonitorNamespaceSelector: {}podMonitorSelector: {}probeNamespaceSelector: {}probeSelector: {}replicas: 1resources:requests:memory: 1000MiruleNamespaceSelector: {}ruleSelector: {}securityContext:fsGroup: 2000runAsNonRoot: truerunAsUser: 1000serviceAccountName: prometheus-k8sserviceMonitorNamespaceSelector: {}serviceMonitorSelector: {}## 在这里添加持久化存储,我这里用的是动态存储。storage:volumeClaimTemplate:metadata:name: prometheus-k8s-dbspec:accessModes: [ "ReadWriteOnce" ]storageClassName: rook-ceph-rbdresources:requests:storage: 50Gi
## 修改默认保存的监控数据为180天retention: 180d   version: 2.46.0

修改好以后重新部署

添加 Prometheus Ingress访问

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: prometheus-ingressnamespace: monitoringlabels:app.kubernetes.io/component: prometheusapp.kubernetes.io/instance: k8sapp.kubernetes.io/name: prometheusapp.kubernetes.io/part-of: kube-prometheusapp.kubernetes.io/version: 2.46.0operator.prometheus.io/mode: server
spec:ingressClassName: nginxrules:- host: prometheus.demo.cnhttp:paths:- backend:service:name: prometheus-k8sport:name: webpath: /pathType: Prefixtls:- hosts:- prometheus.demo.cnsecretName: prometheus.demo.cn

配置好host 直接用域名访问

查看prometheus Targets

没问题的话就继续。
在这里插入图片描述

metrics-server 服务异常

[root@master01 data]# kubectl top node
error: Metrics API not available

解决办法

部署 Grafana 监控面板

修改 Grafana yaml 文件 添加存储,默认的配置是没有存储的。

## 创建PVC存储给 Grafana 使用
apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: grafana-data-pvcnamespace: monitoring
spec:accessModes:- ReadWriteOnceresources:requests:storage: 5GistorageClassName: rook-ceph-rbd
---
apiVersion: apps/v1
kind: Deployment
metadata:labels:app.kubernetes.io/component: grafanaapp.kubernetes.io/name: grafanaapp.kubernetes.io/part-of: kube-prometheusapp.kubernetes.io/version: 9.5.3name: grafananamespace: monitoring
spec:replicas: 1selector:matchLabels:app.kubernetes.io/component: grafanaapp.kubernetes.io/name: grafanaapp.kubernetes.io/part-of: kube-prometheustemplate:metadata:annotations:checksum/grafana-config: 5c598ba58d9b65011bdbb3864138399achecksum/grafana-dashboardproviders: c9c1743868aa1c3dab60d2c402e2dcf0checksum/grafana-datasources: 5ef0e6acaa5b4e8603740fbad440717dlabels:app.kubernetes.io/component: grafanaapp.kubernetes.io/name: grafanaapp.kubernetes.io/part-of: kube-prometheusapp.kubernetes.io/version: 9.5.3spec:automountServiceAccountToken: falsecontainers:- env: []image: grafana/grafana:9.5.3name: grafanaports:- containerPort: 3000name: httpreadinessProbe:httpGet:path: /api/healthport: httpresources:limits:cpu: 200mmemory: 200Mirequests:cpu: 100mmemory: 100MisecurityContext:allowPrivilegeEscalation: falsecapabilities:drop:- ALLreadOnlyRootFilesystem: trueseccompProfile:type: RuntimeDefaultvolumeMounts:- mountPath: /var/lib/grafananame: grafana-storagereadOnly: false- mountPath: /etc/grafana/provisioning/datasourcesname: grafana-datasourcesreadOnly: false- mountPath: /etc/grafana/provisioning/dashboardsname: grafana-dashboardsreadOnly: false- mountPath: /tmpname: tmp-pluginsreadOnly: false- mountPath: /grafana-dashboard-definitions/0/alertmanager-overviewname: grafana-dashboard-alertmanager-overviewreadOnly: false- mountPath: /grafana-dashboard-definitions/0/apiservername: grafana-dashboard-apiserverreadOnly: false- mountPath: /grafana-dashboard-definitions/0/cluster-totalname: grafana-dashboard-cluster-totalreadOnly: false- mountPath: /grafana-dashboard-definitions/0/controller-managername: grafana-dashboard-controller-managerreadOnly: false- mountPath: /grafana-dashboard-definitions/0/grafana-overviewname: grafana-dashboard-grafana-overviewreadOnly: false- mountPath: /grafana-dashboard-definitions/0/k8s-resources-clustername: grafana-dashboard-k8s-resources-clusterreadOnly: false- mountPath: /grafana-dashboard-definitions/0/k8s-resources-multiclustername: grafana-dashboard-k8s-resources-multiclusterreadOnly: false- mountPath: /grafana-dashboard-definitions/0/k8s-resources-namespacename: grafana-dashboard-k8s-resources-namespacereadOnly: false- mountPath: /grafana-dashboard-definitions/0/k8s-resources-nodename: grafana-dashboard-k8s-resources-nodereadOnly: false- mountPath: /grafana-dashboard-definitions/0/k8s-resources-podname: grafana-dashboard-k8s-resources-podreadOnly: false- mountPath: /grafana-dashboard-definitions/0/k8s-resources-workloadname: grafana-dashboard-k8s-resources-workloadreadOnly: false- mountPath: /grafana-dashboard-definitions/0/k8s-resources-workloads-namespacename: grafana-dashboard-k8s-resources-workloads-namespacereadOnly: false- mountPath: /grafana-dashboard-definitions/0/kubeletname: grafana-dashboard-kubeletreadOnly: false- mountPath: /grafana-dashboard-definitions/0/namespace-by-podname: grafana-dashboard-namespace-by-podreadOnly: false- mountPath: /grafana-dashboard-definitions/0/namespace-by-workloadname: grafana-dashboard-namespace-by-workloadreadOnly: false- mountPath: /grafana-dashboard-definitions/0/node-cluster-rsrc-usename: grafana-dashboard-node-cluster-rsrc-usereadOnly: false- mountPath: /grafana-dashboard-definitions/0/node-rsrc-usename: grafana-dashboard-node-rsrc-usereadOnly: false- mountPath: /grafana-dashboard-definitions/0/nodes-darwinname: grafana-dashboard-nodes-darwinreadOnly: false- mountPath: /grafana-dashboard-definitions/0/nodesname: grafana-dashboard-nodesreadOnly: false- mountPath: /grafana-dashboard-definitions/0/persistentvolumesusagename: grafana-dashboard-persistentvolumesusagereadOnly: false- mountPath: /grafana-dashboard-definitions/0/pod-totalname: grafana-dashboard-pod-totalreadOnly: false- mountPath: /grafana-dashboard-definitions/0/prometheus-remote-writename: grafana-dashboard-prometheus-remote-writereadOnly: false- mountPath: /grafana-dashboard-definitions/0/prometheusname: grafana-dashboard-prometheusreadOnly: false- mountPath: /grafana-dashboard-definitions/0/proxyname: grafana-dashboard-proxyreadOnly: false- mountPath: /grafana-dashboard-definitions/0/schedulername: grafana-dashboard-schedulerreadOnly: false- mountPath: /grafana-dashboard-definitions/0/workload-totalname: grafana-dashboard-workload-totalreadOnly: false- mountPath: /etc/grafananame: grafana-configreadOnly: falsenodeSelector:kubernetes.io/os: linuxsecurityContext:fsGroup: 65534runAsNonRoot: truerunAsUser: 65534serviceAccountName: grafanavolumes:## 添加PVC存储- name: grafana-storagepersistentVolumeClaim:claimName: grafana-data-pvc- name: grafana-datasourcessecret:secretName: grafana-datasources- configMap:name: grafana-dashboardsname: grafana-dashboards- emptyDir:medium: Memoryname: tmp-plugins- configMap:name: grafana-dashboard-alertmanager-overviewname: grafana-dashboard-alertmanager-overview- configMap:name: grafana-dashboard-apiservername: grafana-dashboard-apiserver- configMap:name: grafana-dashboard-cluster-totalname: grafana-dashboard-cluster-total- configMap:name: grafana-dashboard-controller-managername: grafana-dashboard-controller-manager- configMap:name: grafana-dashboard-grafana-overviewname: grafana-dashboard-grafana-overview- configMap:name: grafana-dashboard-k8s-resources-clustername: grafana-dashboard-k8s-resources-cluster- configMap:name: grafana-dashboard-k8s-resources-multiclustername: grafana-dashboard-k8s-resources-multicluster- configMap:name: grafana-dashboard-k8s-resources-namespacename: grafana-dashboard-k8s-resources-namespace- configMap:name: grafana-dashboard-k8s-resources-nodename: grafana-dashboard-k8s-resources-node- configMap:name: grafana-dashboard-k8s-resources-podname: grafana-dashboard-k8s-resources-pod- configMap:name: grafana-dashboard-k8s-resources-workloadname: grafana-dashboard-k8s-resources-workload- configMap:name: grafana-dashboard-k8s-resources-workloads-namespacename: grafana-dashboard-k8s-resources-workloads-namespace- configMap:name: grafana-dashboard-kubeletname: grafana-dashboard-kubelet- configMap:name: grafana-dashboard-namespace-by-podname: grafana-dashboard-namespace-by-pod- configMap:name: grafana-dashboard-namespace-by-workloadname: grafana-dashboard-namespace-by-workload- configMap:name: grafana-dashboard-node-cluster-rsrc-usename: grafana-dashboard-node-cluster-rsrc-use- configMap:name: grafana-dashboard-node-rsrc-usename: grafana-dashboard-node-rsrc-use- configMap:name: grafana-dashboard-nodes-darwinname: grafana-dashboard-nodes-darwin- configMap:name: grafana-dashboard-nodesname: grafana-dashboard-nodes- configMap:name: grafana-dashboard-persistentvolumesusagename: grafana-dashboard-persistentvolumesusage- configMap:name: grafana-dashboard-pod-totalname: grafana-dashboard-pod-total- configMap:name: grafana-dashboard-prometheus-remote-writename: grafana-dashboard-prometheus-remote-write- configMap:name: grafana-dashboard-prometheusname: grafana-dashboard-prometheus- configMap:name: grafana-dashboard-proxyname: grafana-dashboard-proxy- configMap:name: grafana-dashboard-schedulername: grafana-dashboard-scheduler- configMap:name: grafana-dashboard-workload-totalname: grafana-dashboard-workload-total- name: grafana-configsecret:secretName: grafana-config

修改好以后重新部署

添加 Grafana Ingress 访问

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: grafana-ingressnamespace: monitoringlabels:app.kubernetes.io/component: grafanaapp.kubernetes.io/name: grafanaapp.kubernetes.io/part-of: kube-prometheusapp.kubernetes.io/version: 9.5.3
spec:ingressClassName: nginxrules:- host: grafana.demo.cnhttp:paths:- backend:service:name: grafanaport:number: 3000path: /pathType: Prefixtls:- hosts:- grafana.demo.cnsecretName: grafana.demo.cn

查看 Grafana 页面

默认账号密码都是admin,首次登陆需要修改密码。部署好以后会有一个默认的配置比如已经添加好了数据源和Dashboard等。
在这里插入图片描述
到此全部部署完成,监控页面有些课鞥呢需要自己自定义配置这里就不再叙述了。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/50295.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

go语言day18 reflect反射

Golang-100-Days/Day16-20(Go语言基础进阶)/day19_Go语言反射.md at master rubyhan1314/Golang-100-Days (github.com) 7-19 接口:底层实现_哔哩哔哩_bilibili 一、interface接口 接口类型内部存储了一对pair(value,Type) type interface { type *Type // 类型信…

Linux:传输层(2) -- TCP协议(2)

目录 1. 流量控制 2. 滑动窗口 3. 拥塞控制 4. 延迟应答 5. 捎带应答 6. 面向字节流 7. 粘包问题 8. TCP异常情况 1. 流量控制 接收端处理数据的速度是有限的. 如果发送端发的太快 , 导致接收端的缓冲区被打满 , 这个时候如果发送端继续发送 , 就会造成丢包, 继而引…

7月24日JavaSE学习笔记

序列化版本控制 序列化:将内存对象转换成序列(流)的过程 反序列化:将对象序列读入程序,转换成对象的方式;反序列化的对象是一个新的对象。 serialVersionUID 是一个类的序列化版本号 private static fin…

oracle 性能指标查询

查看表空间大小以及数据文件大小 select dt.TABLESPACE_NAME, concat(dt.MAX_SIZE,(MB)) total, concat(ddf.total_space,(MB)) used from dba_tablespaces dt,(SELECT tablespace_name,sum(bytes) / (1024 * 1024) total_spaceFROM dba_data_fileswhere TABLESPACE_NAME like…

dsp c6657 SYS/BIOS学习笔记

1 SYS/BIOS简介 SYS/BIOS是一种用于TI的DSP平台的嵌入式操作系统(RTOS)。 2 任务 2.1 任务调度 SYS/BIOS任务线程有0-31个优先级(默认0-15,优先级0被空闲线程使用,任务最低优先级为1,最高优先级为15&am…

使用 EJS 模板引擎的示例

使用 EJS 模板引擎的示例 EJS(Embedded JavaScript)是一种简单的模板引擎,允许你在 HTML 中嵌入 JavaScript 代码。以下是一个使用 EJS 模板引擎的完整示例,包括设置 Express.js 项目、配置 EJS 视图引擎和创建 EJS 模板文件。 …

Java | Leetcode Java题解之第264题丑数II

题目&#xff1a; 题解&#xff1a; class Solution {public int nthUglyNumber(int n) {int[] dp new int[n 1];dp[1] 1;int p2 1, p3 1, p5 1;for (int i 2; i < n; i) {int num2 dp[p2] * 2, num3 dp[p3] * 3, num5 dp[p5] * 5;dp[i] Math.min(Math.min(num2…

2024年网络安全焦点:新兴威胁与防御技术创新

概述 2024年&#xff0c;随着网络技术的发展&#xff0c;网络安全面临的威胁也在不断演变。本文将深入探讨2024年网络安全领域的最新威胁与防御技术创新&#xff0c;并分析它们对企业及个人安全的影响。 新兴威胁分析 云集中风险 随着越来越多的企业将数据和服务迁移至云端…

鸿蒙笔记--存储

这一节了解一下鸿蒙中常用存储API&#xff0c;主要有LocalStorage &#xff0c;AppStorage&#xff0c;PersistentStorage&#xff0c;LocalStorage 是一种页面级UI状态存储机制&#xff0c;主要用于在UIAbility内和页面间共享状态数据。通过使用特定的装饰器&#xff0c;Local…

昇思25天学习打卡营第20天|CV-ResNet50图像分类

打卡 目录 打卡 图像分类 ResNet网络介绍 数据集准备与加载 可视化部分数据集 残差网络构建 Building Block 结构 代码实现 Bottleneck结构 代码实现 构建ResNet50网络 代码定义 模型训练与评估 可视化模型预测 重点&#xff1a;通过网络层数加深&#xff0c;感知…

数据输入输出的概念

文章目录 数据输入输出的概念及在C语言中的实现简单的格式输入与输出用简单的printf函数输出数据用简单的scanf函数输入数据较复杂的输入输出格式控制输出数据格式控制 数据输入输出的概念及在C语言中的实现 数据的输入与输出是相对于计算机而言的。其中&#xff1a; 从计算机…

Linux的shell的date命令

用于生成备份文件的例子 fp"/etc/samba/smb.conf" ; cp -a ${fp} ${fp}.$(date %0y%0m%0d%0H%0M%0S).bak带纳秒ns fp/etc/samba/smb.conf ; cp -a $fp $fp.$(date %0y%0m%0d%0H%0M%0Sns%0N).bakfp/etc/samba/smb.conf ; cp -a $fp $fp.$(date %0y%0m%0d%0…

昇思25天学习打卡营第33天|共赴算力时代

文章目录 一、平台简介二、深度学习模型2.1 处理数据集2.2 模型训练2.3 加载模型 三、共赴算力时代 一、平台简介 昇思大模型平台&#xff0c;就像是AI学习者和开发者的超级基地&#xff0c;这里不仅提供丰富的项目、模型和大模型体验&#xff0c;还有一大堆经典数据集任你挑。…

BM58 字符串的排列

1.题目描述 输入一个长度为 n 字符串&#xff0c;打印出该字符串中字符的所有排列&#xff0c;你可以以任意顺序返回这个字符串数组。 例如输入字符串ABC,则输出由字符A,B,C所能排列出来的所有字符串ABC,ACB,BAC,BCA,CBA和CAB。 数据范围&#xff1a;n<10n<10 要求&#…

本地搭建rtmp拉流

本地搭建rtmp拉流 可按照步骤来 关注公众号&#xff1a;城羽海 更多有趣实用教程 下载地址: 从微信公众号发送关键词 rtmp可获取下载地址 文章目录 本地搭建rtmp拉流 可按照步骤来 关注公众号&#xff1a;城羽海 更多有趣实用教程 拿到之后如图所下&#xff1f;二、配置obs文…

Spark_Oracle_I_通过jdbc读取oracle程序报错invalid character

问题背景&#xff1a; 我原先是通过我么api直接读取的oracle,现在由于要并行读取这个oracle数据库表数据&#xff0c;因此采用jdbc的方式&#xff0c;一开始我把sql变成query直接查&#xff0c;所以报上面的问题。部分样例代码如下 val date "2024/07/01" val quer…

华为网络模拟器eNSP安装部署教程

eNSP是图形化网络仿真平台&#xff0c;该平台通过对真实网络设备的仿真模拟&#xff0c;帮助广大ICT从业者和客户快速熟悉华为数通系列产品&#xff0c;了解并掌握相关产品的操作和配置、提升对企业ICT网络的规划、建设、运维能力&#xff0c;从而帮助企业构建更高效&#xff0…

一个函数统一238个机器学习R包,这也太赞了吧

Caret 是一个试图标准化机器学习过程的一个包。Caret 对 R 中最常用的机器学习方法 (目前支持238个R包)提供了统一的接口。 进行数据预处理 实现机器学习方法流程化模型构建 通过参数组合和交叉验证评估模型的参数 选择最优模型 评估模型性能 一键满足各种掉包&#xff0c…

Linux开启coredump

在Linux系统中&#xff0c;C/C程序崩溃是常见的问题之一。Coredump是指当一个程序崩溃时&#xff0c;系统把程序运行时的内存数据以二进制文件的形式保存下来&#xff0c;以便程序开发者进行崩溃分析。本文将介绍如何开启并配置Coredump 1、查看并配置coredump 在Linux系统中…

JavaScript实战 - 一个能够做圆周运动的模型

一个能够做圆周运动的模型 HTML 文件JavaScript 文件总结 作者&#xff1a;逍遥Sean 简介&#xff1a;一个主修Java的Web网站\游戏服务器后端开发者 主页&#xff1a;https://blog.csdn.net/Ureliable 觉得博主文章不错的话&#xff0c;可以三连支持一下~ 如有需要我的支持&…