helm(一键式部署chart资源)

1、 作用

在没有helm之前,需自定义deployment、service、ingress,helm的作用是通过打包的方式,把deployment、service、ingress打包在一块,一键式部署服务,类似于yum功能。这是官方提供的类似于安装仓库的功能,可以实现一键化部署应用

2、组成部分

****(1)chart:****helm的软件包,包括deployment、service、ingress,是一些定义好的yaml资源,类似于yum的rpm包

****(2)release:****可以理解为版本或在安装过程中给部署的应用起一个名称

****(3)repository:****仓库,提供一个包含chart资源的服务器。yaml资源的保存地址

3、helm2淘汰,helm3纯命令行方式

docker官网下载镜像,github官网下载源码包

helm一键式部署chart资源

1、安装helm(解压缩包)

添加补齐命令

source <(helm completion bash)

2、添加常用仓库

helm repo add bitnami https://charts.bitnami.com/bitnami

helm repo add stable http://mirror.azure.cn/kubernetes/charts

helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts不推荐

helm repo add incubator https://charts.helm.sh/incubator官网

3、查看仓库列表

4、更新仓库资源

helm repo update

5、查看仓库资源

查找指定仓库是否包含nginx的资源

helm search repo bitnami | grep nginx

6、查看chart的详细信息

helm show chart bitnami/nginx(chart信息)

helm show all bitnami/nginx(所有信息)

9、部署chart资源

helm install my-nginx bitnami/nginx -n default

|------------|-----------------------|
| my-nginx | 安装的名称或版本 |
| bitnami | 仓库名 |
| nginx | 指的是chart,一系列yaml资源的集合 |
| -n default | 指定命名空间 |

9、修改chart资源

10、删除chart资源

helm uninstall my-nginx

11、随机生成一个chart资源

helm install bitnami/nginx --generate-name

|-----------------|-----------------|
| --generate-name | 随机生成一个release名称 |

12、查看当前安装的release版本

helm ls

|---|------|
| 1 | 表示回滚 |

13、helm组织结构

根据自己的需求定义chart,然后部署到集群中

14、 自定义chart资源

①创建nginx模板

helm create nginx

|--------------------------|--------------------------------------------|
| charts | 存储依赖环境。若这个chart依赖其他chart,依赖文件会保存在这个目录中 |
| Chart.yaml | helm chart的元数据文件,包含这个chart的名称、版本和维护者信息等 |
| templates | 包含清单模板的目录 |
| deployment.yaml | 部署应用的模板文件 |
| _helpers.tpl | 帮助文档,告诉用户如何定义模板的值 |
| hpa.yaml | 定义应用程序副本数的自动扩缩容行为 |
| ingress.yaml | 定义外部流量如何转发到应用程序 |
| NOTES.txt | 注意事项 |
| serviceaccount.yaml | 应用程序的服务账号 |
| service.yaml | 集群内部的访问配置 |
| tests | 测试目录和文件,chart部署完成后可以用来测试的文件 |
| test-connection.yaml | 测试目录和文件,chart部署完成后可以用来测试的文件 |
| values.yaml 【核心】 | 自定义的值,都是通过values.yaml文件,把自定义的数据覆盖到安装的chart |

②helm自定义访问

这些自定义的值会传给template目录中的各个文件

③验证语法helm lint nginx(在nginx的上一层目录执行此命令)

④打包helm package nginx

⑤部署

• 测试:helm install nginx-11 ./nginx --dry-run --debug

|-------------------|-------------------------------------|
| nginx-11 | release版本号 |
| ./nginx | 当前目录下的nginx的chart |
| --dry-run --debug | 这个集群不会部署到集群中,进行参数验证,测试chart的配置的是否正确 |

• 安装

第一种方式helm install nginx-11 ./nginx -n default

• 删除

第二种方式 helm install nginx-11 ./nginx -n default

• 部署ingress(基于deployment+nodeport模式)

wget https://gitee.com/mirrors/ingress-nginx/raw/nginx-0.30.0/deploy/static/mandatory.yaml

wget https://gitee.com/mirrors/ingress-nginx/raw/nginx-0.30.0/deploy/static/provider/baremetal/service-nodeport.yaml

15、测试访问

16、修改chart文件后重新部署

①修改service类型nodeport,并且不生成ingress

②重新定义chart名称

③验证chart语法

④更新chart资源并访问

17、回滚

版本2取消了ingress,回滚到版本1验证是否存在ingress即可确认回滚成功与否

18、上传harbor仓库

①新建项目②部署chart路径的识别方式

③指定位置安装helm-push

mkdir -p ~/.local/share/helm/plugins/helm-push

cd ~/.local/share/helm/plugins/helm-push

④测试

docker login -u admin -p 123456 https://hub.test.com

⑤打包更新后的nginx

helm package nginx

⑥上传到仓库

helm push nginx-0.2.0.tgz oci://hub.test.com/chart

原因:harbor仓库是https登录的

解决:跳过tls验证

helm push nginx-0.2.0.tgz oci://hub.test.com/chart --insecure-skip-tls-verify

⑦删除所有,从仓库中拉取镜像

helm pull oci://hub.test.com/chart/nginx --version 0.2.0 --insecure-skip-tls-verify

|---------------------------------------------------|-----------------------------------------------------------|
| helm常用命令 ||
| helm repo add 仓库名称 url仓库地址 | 添加仓库 |
| helm repo update | 不加仓库名,就是更新所有仓库 |
| helm repo list(=helm repo ls) | 仓库列表 |
| helm repo remove 仓库名称 | 删除仓库 |
| helm show chart stable/nginx | 查看chart信息 |
| helm show all stable/nginx | 查看详细信息 |
| helm install nginx-11 stable/nginx -n lucky-cloud | 安装chart,安装官网的默认版本 |
| helm uninstall nginx-11 | 删除安装好的chart |
| helm list | 查看已安装的chart |
| 自定义模板 ||
| helm create nginx | 创建一个自定义的chart模板(其中value.yaml最重要,这里的值会传给templates中的yaml文件) |
| 安装 ||
| helm install nginx-11 ./nginx | 目录 |
| helm install nginx-11 ./nginx-0.1.0.tgz | 路径 |
| helm packge nginx | 打包 |
| 回滚 ||
| helm history nginx-11 ||
| helm rollback nginx-11 1 ||

相关推荐
小林up1 小时前
github push:ssh: connect to host github.com port 22
运维·ssh·github
Leinwin8 小时前
微软开源GitHub Copilot Chat,AI编程领域迎新突破
microsoft·github·copilot
草梅友仁11 小时前
草梅 Auth 与 AI 开发心得 | 2025 年第 27 周草梅周报
github·ai编程·视觉设计
qianmoQ14 小时前
GitHub 趋势日报 (2025年07月02日)
github
A5资源网18 小时前
cloudflare配合github搭建免费开源影视LibreTV一个独享视频网站 详细教程
github
mortimer19 小时前
从零到一:构建一个 Chatterbox-TTS API 服务
开源·github·ai编程
真智AI19 小时前
利用 Claude Opus 4 自动化 GitHub 工作流:从安装到实战详解
运维·自动化·github
寻月隐君1 天前
Rust 网络编程实战:用 Tokio 手写一个迷你 TCP 反向代理 (minginx)
后端·rust·github
喜欢吃豆1 天前
快速手搓一个MCP服务指南(九): FastMCP 服务器组合技术:构建模块化AI应用的终极方案
服务器·人工智能·python·深度学习·大模型·github·fastmcp
油泼辣子多加1 天前
2025年06月30日Github流行趋势
github