记一次无法用helm直接安装kube-prometheus的解决过程(helm离线安装)
记一次无法用helm直接安装kube-prometheus的解决过程(helm离线安装)
本文章记录了由于网络问题而无法直接使用helm repo install安装prometheus-community, 转而使用下载源码打包安装的方式的解决过程.
该思路应该也可以扩展到其他开源 charts 项目的离线安装. (前提是能把源码下下来, 偶尔需要科学上网)
1. 概要
$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
Error: looks like "https://prometheus-community.github.io/helm-charts" is not a valid chart repository or cannot be reached: context deadline exceeded (Client.Timeout or context cancellation while reading body)
$ helm install prom bitnami/kube-prometheus
Error: INSTALLATION FAILED: Get "https://registry-1.docker.io/v2/bitnamicharts/kube-prometheus/tags/list": dial tcp 104.244.46.185:443: connect: connection refused
由于多次遇到过因为网络而无法拉取包/镜像的情况, 在添加bitnami源也无法下载后, 于是决定寻找能否通过拉取源码打包的方式安装.
在参考Helm安装部署/添加chart公共仓库/本地仓库搭建文章后, 尝试将源码下载后按照步骤打包→构建索引→发布. 但在使用helm install后, 发现丢失了一些pod.
查看源码的Chart.yaml发现, 添加了dependencies依赖, 但由于依赖的地址https://prometheus-community.github.io/helm-charts本来我就无法访问, 因此丢失了组件.
故需要将这些依赖复制到helm-charts-main/charts/kube-prometheus-stack/charts目录下, 然后再重新打包→构建索引→发布→安装即可.
2. 记录
2.1. 部署本地helm仓库
使用 docker 创建并运行一个 httpd 镜像容器: docker run -d -p 8081:80 -v /var/www:/usr/local/apache2/htdocs httpd.
将容器80端口映射到宿主机8081端口.
将宿主机的/var/www目录挂载到容器内的/usr/local/apache2/htdocs路径, 作为网页文档根目录.
2.2. 把本地仓库添加到helm repo中
$ helm repo add localrepo http://{宿主机ip}:8081/charts
2.3. 准备好源码
下载源码zip: https://github.com/prometheus-community/helm-charts, 解压.
下载 grfana 源码: https://github.com/grafana/helm-charts/tree/main, 解压.
可以将helm-charts-main分别取名为helm-charts-prometheus-community和helm-charts-grafana.
2.4. 把"依赖们"复制到kube-prometheus-stack的charts目录下
kube-prometheus-stack的Chart.yaml文件依赖了以下组件:
dependencies:
- name: crds
version: "0.0.0"
condition: crds.enabled
- name: kube-state-metrics
version: "5.28.*"
repository: https://prometheus-community.github.io/helm-charts
condition: kubeStateMetrics.enabled
- name: prometheus-node-exporter
version: "4.43.*"
repository: https://prometheus-community.github.io/helm-charts
condition: nodeExporter.enabled
- name: grafana
version: "8.8.*"
repository: https://grafana.github.io/helm-charts
condition: grafana.enabled
- name: prometheus-windows-exporter
repository: https://prometheus-community.github.io/helm-charts
version: "0.7.*"
condition: windowsMonitoring.enabled
确认了以上组件都不再需要依赖其他组件后, 将这些组件的 chart 复制到helm-charts-prometheus-community/charts/kube-prometheus-stack/charts目录下.
$ cd helm-charts-prometheus-community/charts/
$ cp kube-state-metrics/ kube-prometheus-stack/charts/ -r
$ cp prometheus-node-exporter/ kube-prometheus-stack/charts/ -r
$ cp prometheus-windows-exporter/ kube-prometheus-stack/charts/ -r
$ cd /xxxxx/helm-charts-grafana/charts/
$ cp grafana/ /xxxxx/helm-charts-prometheus-community/charts/kube-prometheus-stack/charts/ -r
2.5. 打包、发布、安装kube-prometheus-stack
在helm-charts-prometheus-community/charts/的目录环境下执行helm package kube-prometheus-stack/打包为tgz文件, 方便发布.
在/var/www目录下创建一个charts文件夹, 将打包出来的tgz文件移动或复制过去: $ mv kube-prometheus-stack-67.9.0.tgz /var/www/charts/
生成 index.yaml 索引:
$ cd /var/www/charts/
$ helm repo index ./ --url http://{宿主机ip}:8081/charts
$ helm repo update
安装该 pod:
$ kubectl create ns prometheus
$ helm install localrepo/kube-prometheus-stack -n prometheus --version 67.9.0
如果安装失败报错
Error: INSTALLATION FAILED: cannot re-use a name that is still in use, 则需要使用helm -n <namespace> ls -a查询全部安装服务, 使用helm -n <namespace> delete <packagename>删除失败的安装服务后重新安装.
3. 参考文章
更多推荐



所有评论(0)