Helm命令
Helm命令

目录
[toc]
helm相关
查看helm版本
1[root@master1 ~]#helm version
2version.BuildInfo{Version:"v3.7.2", GitCommit:"663a896f4a815053445eec4153677ddc24a0a361", GitTreeState:"clean", GoVersion:"go1.16.10"}
helm帮助命令
1[root@master1 ~]#helm
2The Kubernetes package manager
3
4Common actions for Helm:
5
6- helm search: search for charts
7- helm pull: download a chart to your local directory to view
8- helm install: upload the chart to Kubernetes
9- helm list: list releases of charts
10
11Environment variables:
12
13| Name | Description |
14|------------------------------------|-----------------------------------------------------------------------------------|
15| $HELM_CACHE_HOME | set an alternative location for storing cached files. |
16| $HELM_CONFIG_HOME | set an alternative location for storing Helm configuration. |
17| $HELM_DATA_HOME | set an alternative location for storing Helm data. |
18| $HELM_DEBUG | indicate whether or not Helm is running in Debug mode |
19| $HELM_DRIVER | set the backend storage driver. Values are: configmap, secret, memory, sql. |
20| $HELM_DRIVER_SQL_CONNECTION_STRING | set the connection string the SQL storage driver should use. |
21| $HELM_MAX_HISTORY | set the maximum number of helm release history. |
22| $HELM_NAMESPACE | set the namespace used for the helm operations. |
23| $HELM_NO_PLUGINS | disable plugins. Set HELM_NO_PLUGINS=1 to disable plugins. |
24| $HELM_PLUGINS | set the path to the plugins directory |
25| $HELM_REGISTRY_CONFIG | set the path to the registry config file. |
26| $HELM_REPOSITORY_CACHE | set the path to the repository cache directory |
27| $HELM_REPOSITORY_CONFIG | set the path to the repositories file. |
28| $KUBECONFIG | set an alternative Kubernetes configuration file (default "~/.kube/config") |
29| $HELM_KUBEAPISERVER | set the Kubernetes API Server Endpoint for authentication |
30| $HELM_KUBECAFILE | set the Kubernetes certificate authority file. |
31| $HELM_KUBEASGROUPS | set the Groups to use for impersonation using a comma-separated list. |
32| $HELM_KUBEASUSER | set the Username to impersonate for the operation. |
33| $HELM_KUBECONTEXT | set the name of the kubeconfig context. |
34| $HELM_KUBETOKEN | set the Bearer KubeToken used for authentication. |
35
36Helm stores cache, configuration, and data based on the following configuration order:
37
38- If a HELM_*_HOME environment variable is set, it will be used
39- Otherwise, on systems supporting the XDG base directory specification, the XDG variables will be used
40- When no other location is set a default location will be used based on the operating system
41
42By default, the default directories depend on the Operating System. The defaults are listed below:
43
44| Operating System | Cache Path | Configuration Path | Data Path |
45|------------------|---------------------------|--------------------------------|-------------------------|
46| Linux | $HOME/.cache/helm | $HOME/.config/helm | $HOME/.local/share/helm |
47| macOS | $HOME/Library/Caches/helm | $HOME/Library/Preferences/helm | $HOME/Library/helm |
48| Windows | %TEMP%\helm | %APPDATA%\helm | %APPDATA%\helm |
49
50Usage:
51 helm [command]
52
53Available Commands:
54 completion generate autocompletion scripts for the specified shell
55 create create a new chart with the given name
56 dependency manage a chart's dependencies
57 env helm client environment information
58 get download extended information of a named release
59 help Help about any command
60 history fetch release history
61 install install a chart
62 lint examine a chart for possible issues
63 list list releases
64 package package a chart directory into a chart archive
65 plugin install, list, or uninstall Helm plugins
66 pull download a chart from a repository and (optionally) unpack it in local directory
67 repo add, list, remove, update, and index chart repositories
68 rollback roll back a release to a previous revision
69 search search for a keyword in charts
70 show show information of a chart
71 status display the status of the named release
72 template locally render templates
73 test run tests for a release
74 uninstall uninstall a release
75 upgrade upgrade a release
76 verify verify that a chart at the given path has been signed and is valid
77 version print the client version information
78
79Flags:
80 --debug enable verbose output
81 -h, --help help for helm
82 --kube-apiserver string the address and the port for the Kubernetes API server
83 --kube-as-group stringArray group to impersonate for the operation, this flag can be repeated to specify multiple groups.
84 --kube-as-user string username to impersonate for the operation
85 --kube-ca-file string the certificate authority file for the Kubernetes API server connection
86 --kube-context string name of the kubeconfig context to use
87 --kube-token string bearer token used for authentication
88 --kubeconfig string path to the kubeconfig file
89 -n, --namespace string namespace scope for this request
90 --registry-config string path to the registry config file (default "/root/.config/helm/registry.json")
91 --repository-cache string path to the file containing cached repository indexes (default "/root/.cache/helm/repository")
92 --repository-config string path to the file containing repository names and URLs (default "/root/.config/helm/repositories.yaml")
93
94Use "helm [command] --help" for more information about a command.
95[root@master1 ~]#
helm repo
查看当前helm chart仓库:list命令
1helm repo list == helm repo ls
2
3例子:
4[root@Devops6 ~]#helm repo list
5WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/config
6WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/config
7NAME URL
8stable http://mirror.azure.cn/kubernetes/charts/
9devops6repo http://172.29.9.120/chartrepo/devops6/
helm添加仓库并更新:add命令
1# helm repo add 仓库名称 仓库地址
2
3helm repo add apisix https://charts.apiseven.com
4helm repo update
更新helm仓库:update命令
1helm repo update

查找chart:search命令
1[root@master ~]#helm search --help
2Usage:
3 helm search [command]
4
5Available Commands:
6 hub search for charts in the Artifact Hub or your own hub instance
7 repo search repositories for a keyword in charts
8
9#说明:
10helm search hub 从 artifact hub中搜索
11helm search repo 从本地的仓库搜索
案例:
用 search 命令来搜索可以安装的 chart 包
1[root@master ~]#helm search repo
2或者
3[root@master ~]#helm search repo stable
4NAME CHART VERSION APP VERSION DESCRIPTION
5stable/acs-engine-autoscaler 2.2.2 2.1.1 DEPRECATED Scales worker nodes within agent pools
6stable/aerospike 0.3.1 v4.5.0.5 A Helm chart for Aerospike in Kubernetes
7stable/airflow 5.2.1 1.10.4 Airflow is a platform to programmatically autho...
8stable/ambassador 5.1.0 0.85.0 A Helm chart for Datawire Ambassador
9stable/anchore-engine 1.3.7 0.5.2 Anchore container analysis and policy evaluatio...
10stable/apm-server 2.1.5 7.0.0 The server receives data from the Elastic APM a...
11......
用 search 命令来搜索可以安装的 mysql chart 包:
虽然这里是一个废弃的版本,但是用来做测试是没任何问题的。
1[root@master ~]#helm search repo mysql
2NAME CHART VERSION APP VERSION DESCRIPTION
3stable/mysql 1.6.9 5.7.30 DEPRECATED - Fast, reliable, scalable, and easy...
4stable/mysqldump 2.6.2 2.4.1 DEPRECATED! - A Helm chart to help backup MySQL...
5stable/prometheus-mysql-exporter 0.7.1 v0.11.0 DEPRECATED A Helm chart for prometheus mysql ex...
6stable/percona 1.2.3 5.7.26 DEPRECATED - free, fully compatible, enhanced, ...
7stable/percona-xtradb-cluster 1.0.8 5.7.19 DEPRECATED - free, fully compatible, enhanced, ...
8stable/phpmyadmin 4.3.5 5.0.1 DEPRECATED phpMyAdmin is an mysql administratio...
9stable/gcloud-sqlproxy 0.6.1 1.11 DEPRECATED Google Cloud SQL Proxy
10stable/mariadb 7.3.14 10.3.22 DEPRECATED Fast, reliable, scalable, and easy t...
11[root@master ~]#
推送包到helm chart仓库
本文由 简悦 SimpRead 转码, 原文地址 blog.csdn.net
helm 默认是不带 push 功能的,因此无法直接将本地的 chart 文件直接上传到 ChartMuseum 中。
1、安装插件
1$ helm plugin install https://github.com/chartmuseum/helm-push
2Downloading and installing helm-push v0.10.1 ...
3https://github.com/chartmuseum/helm-push/releases/download/v0.10.1/helm-push_0.10.1_darwin_amd64.tar.gz
4Installed plugin: cm-push
- 直接安装二进制包
1mv helm-cm-push /usr/bin/
2
3[root@Devops6 devops6-npm-service_HELMCI]#helm-cm-push devops6-npm-service-1.1.1.tgz devops6repo
4Pushing devops6-npm-service-1.1.1.tgz to devops6repo...
5Done.


软件包:
链接:https://pan.baidu.com/s/1GvFSkMdRMBloKx8vwxKakA?pwd=0820
提取码:0820
2023.7.9-helm-push

2、使用
先添加对应的 ChartMuseum 地址,
1$ helm repo add chartmuseum http://your-cm-repo:8080
然后可以针对你需要 push 的文件,或者目录,甚至完整的 tgz 包,进行上传,
1$ helm cm-push mychart-0.3.2.tgz chartmuseum
2Pushing mychart-0.3.2.tgz to chartmuseum...
3Done.
如果 CM 开启了验证,需要指定用户名和密码,
1$ helm cm-push mychart-0.3.2.tgz chartmuseum -u username -p password
2Pushing mychart-0.3.2.tgz to chartmuseum...
3Done.
更多参数可以使用 help 命令查看,
1$ helm cm-push --help
2Helm plugin to push chart package to ChartMuseum
3
4Examples:
5
6 $ helm cm-push mychart-0.1.0.tgz chartmuseum # push .tgz from "helm package"
7 $ helm cm-push . chartmuseum # package and push chart directory
8 $ helm cm-push . --version="1.2.3" chartmuseum # override version in Chart.yaml
9 $ helm cm-push . https://my.chart.repo.com # push directly to chart repo URL
10...
参考文档:
helm下载charts包:fetch命令
这里我们可以使用helm fetch stable/mysql命令将包下载下来。
1[root@master1 ~]#helm fetch stable/mysql
2[root@master1 ~]#ll -h mysql-1.6.9.tgz
3-rw-r--r-- 1 root root 12K Apr 4 12:25 mysql-1.6.9.tgz
helm install
部署helm实例:install命令
1## 安装chart
2helm install RELEASE_NAME CHART_NAME
3helm install happy-panda bitnami/wordpress
4
5### 本地 chart 压缩包
6helm install foo foo-0.1.1.tgz
7
8### 解压后的 chart 目录
9helm install foo path/to/foo
10
11### 完整的 URL
12helm install foo https://example.com/charts/foo-1.2.3.tgz
==工作里比较常用的一条命令==【荐】
为了安装一个 chart 包,我们可以使用 helm install 命令,Helm 有多种方法来找到和安装 chart 包,但是最简单的方法当然是使用官方的 stable 这个仓库直接安装:
首先从仓库中将可用的 charts 信息同步到本地,可以确保我们获取到最新的 charts 列表:(一般每次安装/更新时都建议先update下仓库)
1☸ ➜ helm repo update
2Hang tight while we grab the latest from your chart repositories...
3...Successfully got an update from the "stable" chart repository
4Update Complete. ⎈ Happy Helming!⎈
一条命令部署应用:
1案例1:
2[root@master1 ~]#helm upgrade --install longhorn longhorn/longhorn --create-namespace --namespace longhorn-system -f values.yaml
3#说明
4longhorn 应用的名称
5longhorn/longhorn chart包
6upgrade --install 第一次是安装,后面就是更新了
7--create-namespace 如果是本次需要用到的命名空间,可以加上这个参数
8
9案例2:
10[root@master1 ~]#helm upgrade --install traefik ./traefik -f ./traefik/ci/deployment-prod.yaml --create-namespace --namespace kube-system
11Release "traefik" has been upgraded. Happy Helming!
12NAME: traefik
13LAST DEPLOYED: Sun Jan 16 11:55:13 2022
14NAMESPACE: kube-system
15STATUS: deployed
16REVISION: 2
17TEST SUITE: None
helm install 命令可以从多个源进行安装
- chart 仓库(类似于上面我们提到的)
- 本地 chart 压缩包(helm install foo-0.1.1.tgz)
- 本地解压缩的 chart 目录(helm install foo path/to/foo)
- 在线的 URL(helm install fool https://example.com/charts/foo-1.2.3.tgz)
注意:有时helm upgrade –install命令可能下载不下来
有时helm upgrade –install命令可能下载不下来,可以先用helm fetch longhorn/longhorn命令将helm软件包下载下来,然后修改好values.yaml文件,再使用如下命令安装就好:
1helm upgrade --install longhorn . --create-namespace --namespace longhorn-system -f values.yaml
特别注意:做实验时一定要记得当时对values.yaml文件做了哪方面的改动!
不然可能导致helm安装软件失败
-generate-name选项:生成一个随机名称
1[root@master1 ~]#helm install stable/mysql --generate-name
2WARNING: This chart is deprecated
3NAME: mysql-1649031212
4LAST DEPLOYED: Mon Apr 4 08:13:37 2022
5NAMESPACE: default
6STATUS: deployed
7REVISION: 1
8NOTES:
9MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
10mysql-1649031212.default.svc.cluster.local
11
12To get your root password run:
13
14 MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default mysql-1649031212 -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo)
15
16To connect to your database:
17
181. Run an Ubuntu pod that you can use as a client:
19
20 kubectl run -i --tty ubuntu --image=ubuntu:16.04 --restart=Never -- bash -il
21
222. Install the mysql client:
23
24 $ apt-get update && apt-get install mysql-client -y
25
263. Connect using the mysql cli, then provide your password:
27 $ mysql -h mysql-1649031212 -p
28
29To connect to your database directly from outside the K8s cluster:
30 MYSQL_HOST=127.0.0.1
31 MYSQL_PORT=3306
32
33 # Execute the following command to route the connection:
34 kubectl port-forward svc/mysql-1649031212 3306
35
36 mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}
helm升级:upgrade命令
1[root@master1 ~]#helm upgrade mysql stable/mysql -f 01-config.yaml
helm rollback
rollback命令
1## 回滚
2helm history [RELEASE] 命令来查看一个特定 release 的修订版本号。
3helm rollback
4helm rollback [RELEASE] [REVISION]
例子:
1[root@master1 ~]#helm rollback mysql 1
2Rollback was a success! Happy Helming!
helm release
查看与卸载helm实例
11.查看已经安装的release
2[root@master1 ~]#helm list -n apisix #helm ls
3NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
4apisix apisix 1 2022-02-14 07:30:08.608328227 +0800 CST deployed apisix-0.7.2 2.10.0
5或者:
6helm status mysql-1649031212 #查看release的状态
7
82.卸载helm实例
9[root@master1 ~]#helm uninstall apisix -n apisix
10release "apisix" uninstalled
11或者
12➜ helm uninstall mysql-1575619811 --keep-history
13release "mysql-1575619811" uninstalled
也可以在删除的时候使用 --keep-history 参数,则会保留 release 的历史记录,可以获取该 release 的状态就是 UNINSTALLED,而不是找不到 release了:
1➜ helm uninstall mysql-1575619811 --keep-history
2release "mysql-1575619811" uninstalled
3
4➜ helm status mysql-1575619811
5helm status mysql-1575619811
6NAME: mysql-1575619811
7LAST DEPLOYED: Fri Dec 6 16:47:14 2019
8NAMESPACE: default
9STATUS: uninstalled
10...
11
12➜ helm ls -a
13NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
14mysql-1575619811 default 1 2019-12-06 16:47:14.415214 +0800 CST uninstalled mysql-1.5.0 5.7.27
因为 Helm 会在删除 release 后跟踪你的 release,所以你可以审查历史甚至取消删除 release(使用 helm rollback 命令)。
⚠️ 注意:也可以使用helm delete来卸载release
1[root@master ~]#helm ls
2NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
3mysql-1711286279 default 1 2024-03-24 21:18:00.924308284 +0800 CST deployed mysql-1.6.9 5.7.30
4[root@master ~]#helm delete mysql-1711286279
5release "mysql-1711286279" uninstalled
6[root@master ~]#helm ls
7NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
8[root@master ~]#
查看某个release通过-f或者--自定义的值
1[root@master ~]#helm get values mysql
2USER-SUPPLIED VALUES:
3mysqlDatabase: user0db
4mysqlPassword: user0pwd
5mysqlUser: user0
6persistence:
7 enabled: false
8[root@master ~]#
追踪release的状态
1## 追踪release的状态
2helm status happy-panda
查看某个release的历史
1[root@master1 ~]#helm history mysql
查看release安装后对应的k8s资源状态
1[root@master1 ~]#kubectl get all -l release=mysql-1649031212
2NAME READY STATUS RESTARTS AGE
3pod/mysql-1649031212-9df8c986b-8tj8z 1/1 Running 0 2m3s
4
5NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
6service/mysql-1649031212 ClusterIP 10.105.125.254 <none> 3306/TCP 2m4s
7
8NAME READY UP-TO-DATE AVAILABLE AGE
9deployment.apps/mysql-1649031212 1/1 1 1 2m4s
10
11NAME DESIRED CURRENT READY AGE
12replicaset.apps/mysql-1649031212-9df8c986b 1 1 1 2m3s
helm chart
查看一个 chart 包的所有可配置的参数选项
1☸ ➜ helm show values stable/mysql
2## mysql image version
3## ref: https://hub.docker.com/r/library/mysql/tags/
4##
5image: "mysql"
6imageTag: "5.7.30"
7
8strategy:
9 type: Recreate
10
11busybox:
12 image: "busybox"
13 tag: "1.32"
14
15testFramework:
16 enabled: true
17 image: "bats/bats"
18 tag: "1.2.1"
19 imagePullPolicy: IfNotPresent
20 securityContext: {}
21
22## Specify password for root user
23##
24## Default: random 10 character string
25# mysqlRootPassword: testing
26
27## Create a database user
28##
29# mysqlUser:
30## Default: random 10 character string
31# mysqlPassword:
32
33## Allow unauthenticated access, uncomment to enable
34##
35# mysqlAllowEmptyPassword: true
36
37## Create a database
38##
39# mysqlDatabase:
40
41## Specify an imagePullPolicy (Required)
42## It's recommended to change this to 'Always' if the image tag is 'latest'
43## ref: http://kubernetes.io/docs/user-guide/images/#updating-images
44##
45imagePullPolicy: IfNotPresent
46......
查看chart包的特性
1[root@master1 ~]#helm show chart stable/mysql
2apiVersion: v1
3appVersion: 5.7.30
4deprecated: true
5description: DEPRECATED - Fast, reliable, scalable, and easy to use open-source relational
6 database system.
7home: https://www.mysql.com/
8icon: https://www.mysql.com/common/logos/logo-mysql-170x115.png
9keywords:
10- mysql
11- database
12- sql
13name: mysql
14sources:
15- https://github.com/kubernetes/charts
16- https://github.com/docker-library/mysql
17version: 1.6.9
- 如果想要了解更多信息,可以用
helm show all命令:
1➜ helm show all stable/mysql #可以看一些定制特性!
2......
查看一个 chart 包的所有可配置的参数选项
1## 查看chart中的可配置选项
2helm show values CHART_NAME
3helm install -f values.yaml bitnami/wordpress --generate-name
4
5数据传递:
6 --values /-f 指定yaml文件
7 --set 命令行方式对值进行覆盖
helm get values 来查看新设置是否生效
1[root@master1 ~]#helm get values mysql
helm debug命令
1[root@master1 ~]#helm ls --debug
helm template命令 只渲染,不部署
1语法:
2➜ ~ helm template -h
3Usage:
4 helm template [NAME] [CHART] [flags]
5
6Render(渲染) chart templates locally and display the output.
7……
不部署,但可以将最终yaml文件给渲染出来:
1例子:
2$ helm template mysql stable/mysql > mysql.yaml
3$ cat mysql.yaml

关于我
我的博客主旨:
- 排版美观,语言精炼;
- 文档即手册,步骤明细,拒绝埋坑,提供源码;
- 本人实战文档都是亲测成功的,各位小伙伴在实际操作过程中如有什么疑问,可随时联系本人帮您解决问题,让我们一起进步!
🍀 微信二维码 x2675263825 (舍得), qq:2675263825。

🍀 微信公众号 《云原生架构师实战》

🍀 语雀
https://www.yuque.com/xyy-onlyone

🍀 csdn https://blog.csdn.net/weixin_39246554?spm=1010.2135.3001.5421

🍀 知乎 https://www.zhihu.com/people/foryouone

最后
好了,关于本次就到这里了,感谢大家阅读,最后祝大家生活快乐,每天都过的有意义哦,我们下期见!

