K8s - Helm简介
1 - Helm
Helm是Kubernetes的包管理器,使用一个名为Chart的资源模板化并打包Kubernetes资源,比如Deployment,Service,ConfigMap,Ingress等。
也就是说,Helm将清单文件和元数据合并到单个可重用包中,可以自动创建、打包、配置和部署K8s应用程序。
Helm实例化包时使用输入参数来配置资源,也可以使用依赖项实现包安装时复用现有图表。
一些概念
# chart:
- 一个 Helm 包,也被称作图表,包含了运行一个应用所需要的Deployment、Service、Secret、ConfigMap等YAML文件
- Helm Chart将YAML文件和模版打包在一起,可根据参数化值 values.yaml 生成配置文件
- 支持通过不同的values配置文件适配不同的环境
# release:
在 Kubernetes 集群上运行的 Chart 的一个实例。在同一个集群上,一个 Chart 可以安装很多次,每次安装都会创建一个新的 release。
# repository:
用于发布和存储 Chart 的仓库,Helm客户端通过HTTP协议来访问仓库中Chart的索引文件和压缩包。
官方信息
- https://helm.sh/
- Docs https://helm.sh/docs/
- GitHub https://github.com/helm/helm/
- Quickstart https://helm.sh/docs/intro/quickstart/
- https://helm.sh/docs/intro/using_helm/
- https://helm.sh/docs/intro/cheatsheet/
- BestPractices https://helm.sh/docs/chart_best_practices/
2 - Helm存储库
Helm存储库可以托管用于管理应用程序的Chart。
Helm提供了一个CLI,用于从给定的Helm存储库里安装应用程序到指定的Kubernetes环境中。
一些众所周知的软件应用程序的各种稳定Helm图表可以在如下链接中找到
- https://artifacthub.io/
- Kubeapps Hub:https://hub.kubeapps.com/
3 - 安装Helm
官方文档:https://helm.sh/docs/intro/install/
[anliven@anliven ~]$ uname -a
Linux anliven 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[anliven@anliven ~]$
[anliven@anliven ~]$ cat /etc/system-release
CentOS Linux release 7.8.2003 (Core)
[anliven@anliven ~]$
[anliven@anliven ~]$ wget https://get.helm.sh/helm-v3.5.2-linux-amd64.tar.gz
--2021-02-26 10:41:43-- https://get.helm.sh/helm-v3.5.2-linux-amd64.tar.gz
Resolving get.helm.sh (get.helm.sh)... 152.199.39.108, 2606:2800:247:1cb7:261b:1f9c:2074:3c
Connecting to get.helm.sh (get.helm.sh)|152.199.39.108|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12365365 (12M) [application/x-tar]
Saving to: ‘helm-v3.5.2-linux-amd64.tar.gz’
100%[=====================================================================================================================================>] 12,365,365 2.10MB/s in 12s
2021-02-26 10:41:55 (1002 KB/s) - ‘helm-v3.5.2-linux-amd64.tar.gz’ saved [12365365/12365365]
[anliven@anliven ~]$ tar -xvf helm-v3.5.2-linux-amd64.tar.gz
linux-amd64/
linux-amd64/helm
linux-amd64/LICENSE
linux-amd64/README.md
[anliven@anliven ~]$
[anliven@anliven ~]$ ls -l linux-amd64/
total 38936
-rwxr-xr-x 1 anliven anliven 39854080 Feb 4 16:52 helm
-rw-r--r-- 1 anliven anliven 11373 Feb 4 16:54 LICENSE
-rw-r--r-- 1 anliven anliven 3367 Feb 4 16:54 README.md
[anliven@anliven ~]$
[anliven@anliven ~]$ ls -l /usr/local/bin
total 99388
-rw-r--r-- 1 root root 32768 Oct 9 06:12 docker-compose
-rwxrwxr-x 1 anliven anliven 43003904 Oct 14 22:43 kubectl
-rwxr-xr-x 1 root root 58733392 Oct 14 22:46 minikube
[anliven@anliven ~]$
[anliven@anliven ~]$ sudo mv linux-amd64/helm /usr/local/bin # 将helm命令加入到$PATH
[anliven@anliven ~]$
[anliven@anliven ~]$ helm version # Helm v3与v2变化巨大,没有了tiller
version.BuildInfo{Version:"v3.5.2", GitCommit:"167aac70832d3a384f65f9745335e9fb40169dc2", GitTreeState:"dirty", GoVersion:"go1.15.7"}
[anliven@anliven ~]$
[anliven@anliven ~]$ helm repo remove stable # 删除默认的源
Error: no repositories configured
[anliven@anliven ~]$
[anliven@anliven ~]$ helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts # 增加国内镜像源
"stable" has been added to your repositories
[anliven@anliven ~]$
[anliven@anliven ~]$ helm repo update # 获取最新的charts列表
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈Happy Helming!⎈
[anliven@anliven ~]$
[anliven@anliven ~]$ helm repo list # 查看helm源添加情况
NAME URL
stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
[anliven@anliven ~]$
4 - Helm的一般操作
- cheatsheet: https://helm.sh/docs/intro/cheatsheet/
- Helm Commands: https://helm.sh/docs/helm/helm/
# 特别注意,多使用 --drun-run 参数进行操作的事前验证
helm repo add # 添加Helm repo
helm repo update # 更新Helm repo
helm search # 搜索chart
helm pull # 下载chart到本地目录
helm list # 列出已发布的chart
helm create # 生成图表骨架
helm package # 打包,将一个包含多个Kubenetes清单文件的应用程序打包为Helm包
helm install {release_name} . # 进行本地安装
helm install {releace_name} -f values.yaml # 指定文件进行本地安装
helm uninstall {release_name} # 卸载 release
helm status {release_name} # 查看部署状态/进度
helm history {release_name} # 查看历史版本
helm rollback # 回滚
helm show all # 查看所有chart信息
helm show values {release_name} # 查看安装参数(已安装chart的values.yaml)
helm edit values {release_name} # 修改安装参数(修改已安装chart的values.yaml)
helm upgrade {release_name} --set service.type="NodePort" . # 进行本地升级release
helm upgrade {release_name} -f values.yaml # 指定文件进行本地升级
helm plugin list # 列出插件
helm plugin install # 从指定url安装插件
helm plugin uninstall # 卸载插件
helm plugin update # 更新插件
5 - 前提条件
使用Helm需要以下前置条件:
- 一个 Kubernetes 集群和本地的 kubectl
- Helm和Kubernetes的版本对应支持,https://helm.sh/docs/topics/version_skew/
- 安装和配置Helm
6 - Helm 插件
- Helm Push 允许将本地的 Helm Charts 推送到远程存储库,方便与他人共享和分发。
- Helm Diff 比较当前部署和最新版本的 Helm Chart 之间的差异,并显示出具体的变化,方便进行版本控制和更新。
- Helm Secrets 用于对敏感信息进行加密和解密的插件,可以在 Helm Chart 中存储和管理加密的数据。
- Helm Git 允许从 Git 存储库中直接安装和更新 Helm Charts,方便管理和跟踪 Chart 的版本。
- Helmfile 允许将多个 Helm Charts 组织成一个项目,并根据需要进行统一的部署和管理。
- Helm Test 用于运行 Helm Chart 中定义的测试套件,以确保部署的应用程序正常运行。
行动是绝望的解药!
欢迎转载和引用,但请在明显处保留原文链接和原作者信息!
本博客内容多为个人工作与学习的记录,少数内容来自于网络并略有修改,已尽力标明原文链接和转载说明。如有冒犯,即刻删除!
以所舍,求所得,有所获,方所成。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
2016-12-26 读书笔记--SQL必知必会12--联结表
2016-12-26 TS - On Duty