如何使用 Helm 在 K8s 上集成 Prometheus 和 Grafana|Part 2
在 Part 1 中,我们一起了解了什么是 Prometheus 和 Grafana,以及使用这些工具的前提条件和优势。在本部分,将继续带您学习如何安装 Helm 以及如何使用 Prometheus Helm Charts。
开始使用 Helm 和 Helm Chart
ArtifactHub 为 Helm Chart 提供了公共和私有资源库。我们将使用这些 Helm Chart 来设置 Kubernetes 集群中的 pod 和服务。
Helm 社区为各种 Kubernetes 应用程序创建、管理和维护 Helm Chart,这些资源会时常更新。Helm Chart 可重复使用,安装简单。想要使用 Helm 在 Kubernetes 上集成 Prometheus 和 Grafana,让我们从安装 Helm 开始。
安装 Helm
安装 Helm 之前,必须使用以下命令启动 Minikube Kubernetes:
minikube start --driver=docker
下图显示 Minikube 正在运行。Kubectl 工具现已配置为使用 Minikube。

接下来,使用以下命令(根据你使用的操作系统使用对应的命令)安装 Helm:
在 Linux 上安装 Helm
sudo apt-get install helm
在 Windows 上安装 Helm
choco install Kubernetes-helm
在 macOS 系统上安装 Helm
brew install helm
提示:如果遇到问题,可以查看 Helm 官方文档指南 https://helm.sh/docs/intro/install/。
下图显示了 Helm 在 Windows 机器上的安装情况:

Helm 命令
要获取所有 Helm 命令,请运行此命令:
helm
命令输出结果:
The Kubernetes package manager
Common actions for Helm:
- helm search: search for charts
- helm pull: download a chart to your local directory to view
- helm install: upload the chart to Kubernetes
- helm list: list releases of charts
Usage:
helm [command]
Available Commands:
completion generate autocompletion scripts for the specified shell
create create a new chart with the given name
dependency manage a chart's dependencies
env helm client environment information
get download extended information of a named release
help Help about any command
history fetch release history
install install a chart
lint examine a chart for possible issues
list list releases
package package a chart directory into a chart archive
plugin install, list, or uninstall Helm plugins
pull download a chart from a repository and (optionally) unpack it in local directory
push push a chart to remote
registry login to or logout from a registry
repo add, list, remove, update, and index chart repositories
rollback roll back a release to a previous revision
search search for a keyword in charts
show show information of a chart
status display the status of the named release
template locally render templates
test run tests for a release
uninstall uninstall a release
upgrade upgrade a release
verify verify that a chart at the given path has been signed and is valid
version print the client version information
Use "helm [command] --help" for more information about a command.
最常用的 Helm 命令有
- helm search:在 ArtifactHub 资源库中搜索 Helm Chart。
- helm pull:从 ArtifactHub 资源库中提取并下载 Helm Chart。
- helm install:上传 Helm Chart 并将其部署到 Kubernetes 集群。
- helm list:列出 Kubernetes 集群中部署的所有 Helm Chart。
Prometheus Helm Charts
首先,我们将搜索 Prometheus Helm Charts。要搜索 Prometheus Helm,请运行以下命令:
helm search hub prometheus
该命令列出以下 Prometheus Helm Chart:
URL CHART VERSION APP VERSION DESCRIPTION
https://artifacthub.io/packages/helm/prometheus... 25.1.0 v2.47.0 Prometheus is a monitoring system and time seri...
https://artifacthub.io/packages/helm/truecharts... 13.0.7 2.47.1 kube-prometheus-stack collects Kubernetes manif...
https://artifacthub.io/packages/helm/saurabh6-p... 0.2.0 1.1 This is a Helm Chart for Prometheus Setup.
https://artifacthub.io/packages/helm/prometheus... 13.0.0 2.22.1 Prometheus is a monitoring system and time seri...
https://artifacthub.io/packages/helm/wenerme/pr... 25.1.0 v2.47.0 Prometheus is a monitoring system and time seri...
https://artifacthub.io/packages/helm/wener/prom... 25.1.0 v2.47.0 Prometheus is a monitoring system and time seri...
https://artifacthub.io/packages/helm/romanow-he... 1.3.5 2.40.0 Prometheus collects and stores its metrics as t...
https://artifacthub.io/packages/helm/mach1el-ch... 1.0.1 v2.47.0 Prometheus Helm chart for Kubernetes
https://artifacthub.io/packages/helm/cloudposse... 0.2.1 Prometheus instance created by the CoreOS Prome...
您还可以前往 ArtifactHub 存储库(https://artifacthub.io/)并搜索官方 Prometheus Helm Chart,如下图所示:

列表中的第一个是官方的 Prometheus Helm Chart。要获取此 Helm Chart,请运行以下命令:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
输出结果:
"prometheus-community" has been added to your repositories
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "grafana" chart repository
...Successfully got an update from the "prometheus-community" chart repository
...Successfully got an update from the "bitnami" chart repository
Update Complete. ⎈Happy Helming!⎈
现在,我们已经下载好最新版本的 Prometheus 了。
在 K8s 集群上安装 Prometheus Helm Chart
要在 K8s 集群上安装 Prometheus Helm Chart,请运行以下helm install命令:
helm install prometheus prometheus-community/prometheus
输出结果:
NAME: my-prometheus
LAST DEPLOYED: Thu Oct 12 20:06:57 2023
NAMESPACE: monitoring
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
The Prometheus server can be accessed via port 80 on the following DNS name from within your cluster:
my-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.kubernetes.io/name=prometheus,app.kubernetes.io/instance=my-prometheus" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace monitoring port-forward $POD_NAME 9090
The Prometheus alertmanager can be accessed via port 9093 on the following DNS name from within your cluster:
my-prometheus-alertmanager.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.kubernetes.io/name=alertmanager,app.kubernetes.io/instance=my-prometheus" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace monitoring port-forward $POD_NAME 9093
#################################################################################
###### 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-prometheus-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/
现在我们已经在 Kubernetes 集群上安装了 Prometheus。我们可以通过80端口访问 Prometheus 服务器。下一步是查看部署的 Kubernetes 资源,也就是 Helm Chart 在 Kubernetes 集群中创建的 Pod 和服务。
要查看已部署的 Kubernetes 资源,请运行以下kubectl命令:
kubectl get all
输出结果:
NAME READY STATUS RESTARTS AGE
pod/my-prometheus-prometheus-node-exporter-d5l8m 1/1 Running 0 27m
pod/my-prometheus-prometheus-node-exporter-kfbxb 1/1 Running 0 27m
pod/my-prometheus-prometheus-pushgateway-86d6f795cb-mlb7d 1/1 Running 0 27m
pod/my-prometheus-kube-state-metrics-6c4b65c7b9-wbh9r 1/1 Running 0 27m
pod/my-prometheus-prometheus-node-exporter-2z7rp 1/1 Running 0 27m
pod/my-prometheus-alertmanager-0 1/1 Running 0 27m
pod/my-prometheus-server-795d8fc685-zcfct 2/2 Running 0 27m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/my-prometheus-alertmanager-headless ClusterIP None <none> 9093/TCP 27m
service/my-prometheus-server ClusterIP 10.43.186.10 <none> 80/TCP 27m
service/my-prometheus-prometheus-pushgateway ClusterIP 10.43.154.83 <none> 9091/TCP 27m
service/my-prometheus-alertmanager ClusterIP 10.43.217.41 <none> 9093/TCP 27m
service/my-prometheus-kube-state-metrics ClusterIP 10.43.168.65 <none> 8080/TCP 27m
service/my-prometheus-prometheus-node-exporter ClusterIP 10.43.195.241 <none> 9100/TCP 27m
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
daemonset.apps/my-prometheus-prometheus-node-exporter 3 3 3 3 3 kubernetes.io/os=linux 27m
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/my-prometheus-prometheus-pushgateway 1/1 1 1 27m
deployment.apps/my-prometheus-kube-state-metrics 1/1 1 1 27m
deployment.apps/my-prometheus-server 1/1 1 1 27m
NAME DESIRED CURRENT READY AGE
replicaset.apps/my-prometheus-prometheus-pushgateway-86d6f795cb 1 1 1 27m
replicaset.apps/my-prometheus-kube-state-metrics-6c4b65c7b9 1 1 1 27m
replicaset.apps/my-prometheus-server-795d8fc685 1 1 1 27m
NAME READY AGE
statefulset.apps/my-prometheus-alertmanager 1/1 27m
安装 Helm Chart 会创建以下 Kubernetes 资源:
- Pod:托管集群内已部署的 Prometheus Kubernetes 应用程序。
- Replica Sets:Kubernetes 集群内同一应用程序实例的集合。它提高了应用程序的可靠性。
- Deployments:这是创建应用程序 Pod 的蓝图。
- Services:这是公开 Kubernetes 集群内运行的 Pod。我们用它来访问已部署的 Kubernetes 应用程序。
下一步是访问并启动 Prometheus Kubernetes 应用程序。这里将使用 Prometheus 的 Kubernetes 服务访问该应用程序。要获取 Prometheus 的所有 Kubernetes 服务,请运行以下命令:
kubectl get service
输出结果:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-prometheus-alertmanager-headless ClusterIP None <none> 9093/TCP 28m
my-prometheus-server ClusterIP 10.43.186.10 <none> 80/TCP 28m
my-prometheus-prometheus-pushgateway ClusterIP 10.43.154.83 <none> 9091/TCP 28m
my-prometheus-alertmanager ClusterIP 10.43.217.41 <none> 9093/TCP 28m
my-prometheus-kube-state-metrics ClusterIP 10.43.168.65 <none> 8080/TCP 28m
my-prometheus-prometheus-node-exporter ClusterIP 10.43.195.241 <none> 9100/TCP 28m
输出结果列出了 Prometheus 的下列 K8s service:
prometheus-alertmanagerprometheus-alertmanager-headlessprometheus-kube-state-metricsprometheus-prometheus-node-exporterprometheus-prometheus-pushgatewayprometheus-server
我们将使用 prometheus-server Kubernetes service 来访问 Prometheus 应用程序。prometheus-server 是 ClusterIP 类型。您只能在 Kubernetes 集群内访问它。因此我们需要公开这个 Kubernetes service,以便在 Kubernetes 集群外部访问它。公开prometheus-server Kubernetes service 将生成一个 URL。我们可以在浏览器上加载 URL 并访问正在运行的应用程序。
公开 prometheus-server Kubernetes service
要公开prometheus-server Kubernetes service,请运行以下命令:
kubectl expose service prometheus-server --type=NodePort --target-port=9090 --name=prometheus-server-ext
该命令会将ClusterIP类型转换为NodePort类型。这样, prometheus-server就能在 Kubernetes 集群之外通过 9090 端口访问。
现在,我们公开了prometheus-server Kubernetes service。接下来使用以下命令访问 Prometheus 应用程序:
minikube service prometheus-server-ext
该命令生成以下 URL:

URL 可能需要稍等一会儿才可用。您需要在浏览器上进行多次重试,直到使用此 URL 访问 Prometheus Kubernetes 应用程序。您还需要保持终端打开并运行命令,以便继续访问服务。

到这里,我们已经成功使用 Helm 在 Kubernetes 上安装了 Prometheus。Prometheus 已经在集群内部运行,我们可以使用浏览器或 URL 来进行访问。
如何使用 Helm 在 K8s 上集成 Prometheus 和 Grafana|Part 2的更多相关文章
- helm在k8s上部署Elasticsearch和Kibana
前提 在win上安装docker desktop,没有网络限制,而且,打开kubernetes之后,很快就安装启动好了. 在win上安装scoop,有网络限制,需要访问github raw的文件内容, ...
- 【集群监控】Docker上部署Prometheus+Alertmanager+Grafana实现集群监控
Docker部署 下载 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.re ...
- 部署 Prometheus 和 Grafana 到 k8s
在 k8s 中部署 Prometheus 和 Grafana Intro 上次我们主要分享了 asp.net core 集成 prometheus,以及简单的 prometheus 使用,在实际在 k ...
- 有状态软件如何在 k8s 上快速扩容甚至自动扩容
概述 在传统的虚机/物理机环境里, 如果我们想要对一个有状态应用扩容, 我们需要做哪些步骤? 申请虚机/物理机 安装依赖 下载安装包 按规范配置主机名, hosts 配置网络: 包括域名, DNS, ...
- asp.net core 集成 Prometheus
asp.net core 集成 prometheus Intro Prometheus 是一个开源的现代化,云原生的系统监控框架,并且可以轻松的集成 PushGateway, AlertManager ...
- 手把手教你玩转 Gitea|使用 Helm 在 K3s 上安装 Gitea
前言 在前面的文章中,演示了如何用 Docker 镜像和 Windows 二进制包来安装运行 Gitea.今天是玩转 Gitea 系列的使用 Helm 在 K3s 上安装 Gitea. 关于 Gite ...
- 在k8s上安装Jenkins及常见问题
持续集成和部署是DevOps的重要组成部分,Jenkins是一款非常流行的持续集成和部署工具,最近试验了一下Jenkins,发现它是我一段时间以来用过的工具中最复杂的.一个可能的原因是它需要与各种其它 ...
- 在k8s上部署日志系统elfk
日志系统elfk 前言 经过上周的技术预研,在本周一通过开会研究,根据公司的现有业务流量和技术栈,决定选择的日志系统方案为:elasticsearch(es)+logstash(lo)+filebea ...
- gitlab在k8s上运行的一些优化
由 林坤创建,最终由 林坤修改于七月02,2020 gitlab组件图 gitlab在k8s上占用资源 kubectl top pods -n default | grep git* gitlab-g ...
- 优化:在k8s上部署的gitlab
gitlab组件图 gitlab在k8s上占用资源 # kubectl top pods -n default | grep git* gitlab-gitaly-0 9m 444Mi gitlab- ...
随机推荐
- 运行在容器中Postgres数据库数据损坏后如何恢复?
前言 在使用 K8S 部署 RSS 全套自托管解决方案- RssHub + Tiny Tiny Rss, 我介绍了将 RssHub + Tiny Tiny RSS 部署到 K8s 集群中的方案. 其中 ...
- ida反汇编失败
options->general->打开堆栈指针(stack pointer) 可见反汇编失败提示的地址(本程序为00101481,原本此处不为000)处堆栈指针不为0,因此需要修改 al ...
- Jenkins集成maven/gitlab-代码拉取
Jenkins插件-加速-上传安装-离线安装 1.加速插件(国外的源替换成国内的源-->系统管理-->插件管理-->高级-->升级站点-->修改URL) 清华源链接:ht ...
- codeforces div1A
A. Circular Local MiniMax 题目翻译:给我们一个数组(循环的也就是1和n是相邻的),我们可以对数组进行任意调序,对于每个数b[i]要求满足b[i] < b[i - 1] ...
- React 基础介绍以及demo实践
这篇文章是之前给新同事培训react基础所写的文章,现贴这里供大家参考: 1.什么是React? React 是一个用于构建用户界面的JavaScript库核心专注于视图,目的实现组件化开发 2.组件 ...
- MySQL简易教程
本文是参考廖雪峰老师的,但是网站广告有点多,我就在本地抄写一份,一方面是为了加强记忆巩固基础,另一方面也是就是为了第一方面.廖雪峰老师Mysql教程直达地址:https://www.liaoxuefe ...
- 【日常收支账本】【Day04】优化编辑动账记录的操作——QTableWidget单元格设置QComboBox控件
一.项目地址 https://github.com/LinFeng-BingYi/DailyAccountBook 二.新增 1. 在表格中设置选项列表,让用户更快地编辑动账记录 1.1 功能详述 为 ...
- GitHub Actions 入门指南
前言 GitHub Actions 可以构建一组自动化的工作流程,并提供了拉取请求.合并分支等事件来触发他们.一般成熟的开源项目会在每个版本发布时提供 releases ,它就是通过 Actions ...
- 三维形体的表面积(3.25leetcode每日打卡)
在 N * N 的网格上,我们放置一些 1 * 1 * 1 的立方体. 每个值 v = grid[i][j] 表示 v 个正方体叠放在对应单元格 (i, j) 上. 请你返回最终形体的表面积. ...
- 大白话说Python+Flask入门(二)
写在前面 笔者技术真的很一般,也许只靠着笨鸟先飞的这种傻瓜坚持,才能在互联网行业侥幸的生存下来吧! 为什么这么说? 我曾不止一次在某群,看到说我写的东西一点技术含量都没有,而且很没营养,换作一年前的我 ...