文章

helm常用命令

常用命令

1. 添加常用源

1
2
3
4
helm repo add stable https://kubernetes-charts.storage.googleapis.com
helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com  
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add aliyuncs https://apphub.aliyuncs.com

2. 查看当前发布服务的详情

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
1. 列出所有 Helm 发布
helm list
helm -n nsname list

2. 获取特定 Helm 发布的详细信息
helm get all <release-name>
helm get all <release-name> -n nsname

3. 查看特定 Helm 发布的历史:
helm history <release-name>
helm history <release-name> -n nsname

4. 查看特定 Helm 发布的值:
helm get values <release-name>
helm get values <release-name> -n nsname

5. 查看特定 Helm 发布的清单: 会列出helm生成的yaml 详情
helm get manifest <release-name> -n nsname

3. 回滚版本

回滚服务名: abc

命名空间: prod

1.查看当前发布版本

1
helm history -n prod abc
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Sat Jul 27 16:09:46 2024 superseded base-chart-0.0.9   abc:20240703-14-30-2260169-release
2 Wed Aug 28 14:43:08 2024 superseded base-chart-0.0.9   abc:20240828-14-35-502983-release

2.回滚到指定版本

1
helm rollback -n prod abc 1

4.下载包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
配置存储库
helm repo add seldonio https://storage.googleapis.com/seldon-charts
helm repo update

查看存储库
helm repo list
helm search repo seldonio

下载指定包
helm pull seldonio/seldon-core-operator

删除存储库
helm repo remove seldonio

5. 更新Chart包

(1). 打包

引用当前的yaml文件:

~]# helm package .

(2). 替换包

1>. 未安装过此包

helm push 打包过的文件 http://地址

地址获取: helm repo list

2>.已安装过此包

可直接删除加载包位置的源码包: rm -rf 包名

复制新包到此目录下: cp 包名 目的地址

(3). 更新包

在对应的可使用kubectl控制pod启动的服务器上分别执行: helm repo update

否则不生效

6. 查看chart包源

1
2
3
helm repo list

helm search repo

7. 创建包

1
helm create mychart

常见问题

1.data: Too long: may not be more than 1048576 bytes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
> helm upgrade --install -n monitor prometheus ../kube-prometheus-stack -f ${values_yaml} --debug

-------------------------------------------------------------
install.go:225: 2025-07-23 15:01:59.429596142 +0800 CST m=+0.035829219 [debug] Original chart version: ""
install.go:242: 2025-07-23 15:01:59.429655618 +0800 CST m=+0.035888694 [debug] CHART PATH: /home/yingliang/DataStorage/HelmChart/kube-prometheus-stack/kube-prometheus-stack

history.go:56: 2025-07-23 15:02:00.933606955 +0800 CST m=+1.413412077 [debug] getting history for release prometheus
Release "prometheus" does not exist. Installing it now.
install.go:225: 2025-07-23 15:02:01.127119527 +0800 CST m=+1.606924615 [debug] Original chart version: ""
...
...
...
Error: create: failed to create: Secret "sh.helm.release.v1.prometheus.v1" is invalid: data: Too long: may not be more than 1048576 bytes
helm.go:92: 2025-07-23 15:02:24.55070606 +0800 CST m=+25.030511152 [debug] Secret "sh.helm.release.v1.prometheus.v1" is invalid: data: Too long: may not be more than 1048576 bytes
create: failed to create
helm.sh/helm/v3/pkg/storage/driver.(*Secrets).Create
	helm.sh/helm/v3/pkg/storage/driver/secrets.go:168
helm.sh/helm/v3/pkg/storage.(*Storage).Create
	helm.sh/helm/v3/pkg/storage/storage.go:69
helm.sh/helm/v3/pkg/action.(*Install).RunWithContext
	helm.sh/helm/v3/pkg/action/install.go:401
main.runInstall
	helm.sh/helm/v3/cmd/helm/install.go:317
main.newUpgradeCmd.func2
	helm.sh/helm/v3/cmd/helm/upgrade.go:160
github.com/spf13/cobra.(*Command).execute
	github.com/spf13/cobra@v1.9.1/command.go:1015
github.com/spf13/cobra.(*Command).ExecuteC
	github.com/spf13/cobra@v1.9.1/command.go:1148
github.com/spf13/cobra.(*Command).Execute
	github.com/spf13/cobra@v1.9.1/command.go:1071
main.main
	helm.sh/helm/v3/cmd/helm/helm.go:91
runtime.main
	runtime/proc.go:283
runtime.goexit
	runtime/asm_amd64.s:1700

原因: 当前helm-chart目录下文件太大了(不仅是生成的yaml,还有根目录中没有必要的文件),非helm 最终生效的 yaml 文件

解决方法:

方法1. 将无关的文件移除 helm-chart 目录即可

方法2. 将无关的文件或目录加入 .helmignore 文件中也可以

本文由作者按照 CC BY 4.0 进行授权