Helm v3 命令详解

Helm 是云原生领域最火热的应用管理工具。众所周知 Kubernetes 是自动化的容器管理平台,然而 Kubernetes 并没有抽象出应用的概念,通常应用的描述是非常复杂的,一个应用可能是由多种资源组成。

我们通过多次 kubectl apply -f 上述资源,但是后续无法有效管理应用所包含的资源。这也正是 Helm 要解决的难题,更好地帮助用户定义、部署以及管理应用。

1. helm version

1
2
3
4
5

# 查看版本
$ helm version
version.BuildInfo{Version:"3.15.4", GitCommit:"fa9efb07d9d8debbb4306d72af76a383895aa8c4", GitTreeState:"clean", GoVersion:"go1.22.6"}

1
2
3
4
5

# 查看短版本
$ helm version --short
3.15.4+gfa9efb0

2. helm help

1
2
3
4
5
6
7
8
9
10
11
12
查看命令行帮助,有以下几种方式:

helm
helm help
helm help [command]
helm -h(常用)
helm --help
helm [command] -h(常用)
helm [command] -help
helm [command] [sub command] -h(常用)
helm [command] [sub command] -help
查看命令行帮助。

3. helm env

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

$ helm env

HELM_BIN="helm"
HELM_BURST_LIMIT="100"
HELM_CACHE_HOME="/home/your_id/.cache/helm"
HELM_CONFIG_HOME="/home/your_id/.config/helm"
HELM_DATA_HOME="/home/your_id/.local/share/helm"
HELM_DEBUG="false"
HELM_KUBEAPISERVER=""
HELM_KUBEASGROUPS=""
HELM_KUBEASUSER=""
HELM_KUBECAFILE=""
HELM_KUBECONTEXT=""
HELM_KUBEINSECURE_SKIP_TLS_VERIFY="false"
HELM_KUBETLS_SERVER_NAME=""
HELM_KUBETOKEN=""
HELM_MAX_HISTORY="10"
HELM_NAMESPACE="default"
HELM_PLUGINS="/home/your_id/.local/share/helm/plugins"
HELM_QPS="0.00"
HELM_REGISTRY_CONFIG="/home/your_id/.config/helm/registry/config.json"
HELM_REPOSITORY_CACHE="/home/your_id/.cache/helm/repository"
HELM_REPOSITORY_CONFIG="/home/your_id/.config/helm/repositories.yaml"

4. Helm repo

4.1. 增加仓库

增加仓库,以下命令为增加 helm 官方 stable 仓库,命令中 stable 为仓库名称,链接为仓库的 Chart 清单文件地址。当增加仓库时,Helm 会将仓库的 Chart 清单文件下载到本地并存放到 Kubernetes 中,以后 helm search、install 和 pull 等操作都通过仓库名称到 Kubernetes 中查找该仓库相关的 Chart 包。可以注意到官方的 stable 仓库的地址和 Helm Hub 地址是不同的,两者是独立存在的,stable 仓库只是众多公共仓库之一,但是是 Helm 官方提供的。

1
2
3
4
# helm repo add

helm repo add stable https://charts.helm.sh/stable

以下为官方 stable 仓库的清单文件,地址https://charts.helm.sh/stable。可以看出就是一个个 Chart 包的信息,按照字母顺序排列,而且只到 D 开头的 Chart 包,所有 Chart 清单应该分片为多个清单文件,应该多次请求才能全部下载下来。也可以直接访问https://charts.helm.sh/stable/ambassador-5.3.1.tgz将 tgz 包下载下来。

以下为几个常用的仓库的添加命令。

1
2
3
4
5
6

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
helm repo add kong https://charts.konghq.com

1
2
3
4
5
6
7
8
9
10
$ helm repo list
查看加到本地的仓库列表
$ helm repo list
NAME URL
stable https://charts.helm.sh/stable
aliyuncs https://apphub.aliyuncs.com
bitnami https://charts.bitnami.com/bitnami
incubator https://kubernetes-charts-incubator.storage.googleapis.com
kong https://charts.konghq.com

Helm v3 取消了 v2 的 local repo,Helm v3 本地增加的仓库列表存放在/root/.config/helm/repositories.yaml

1
cat /root/.config/helm/repositories.yaml

仓库的 Chart 清单应该是存储在 Kubernetes 的 etcd 中,但在/root/.cache/helm/repository 存储了备份。下载的 Chart 包也缓存在该目录下

1
2
3
4
$ ls /root/.cache/helm/repository
aliyuncs-index.yaml bitnami-index.yaml kong-index.yaml nginx-5.1.4.tgz tomcat-6.1.3.tgz
ambassador-6.1.1.tgz incubator-index.yaml mysql-1.6.2.tgz stable-index.yaml

移除本地仓库

1
2
3
4
5

$ helm repo remove
helm repo remove kong
"kong" has been removed from your repositories

更新本地仓库

1
2
3
4
5
6
7
8
9
10
11

# helm repo update
$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "kong" chart repository
...Successfully got an update from the "incubator" chart repository
...Successfully got an update from the "aliyuncs" chart repository
...Successfully got an update from the "bitnami" chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈

查询 Chart 包,查询命令分为 helm search hub 和 helm search repo。

helm search hub 搜索Artifact Hub,其中列出了来自数十个不同存储库的 helm Chart。

helm search repo,从所有加到本地的仓库中查找应用,这些仓库加到本地时 Chart 清单文件已被存放到 Kubernetes 中,所以查找应用时无需联网。

从 Helm Hub 中查询 Chart,而且只展示最新 Chart 版本。

1
2
3

helm search hub elasticsearch

从本地的仓库列表中查询 Chart,而且只展示 Chart 最新版本。注意 Chart 包本身有版本号,区别于 Chart 包中应用的版本号。

1
2
3
4
5
6
7

$ helm search repo elasticsearch
NAME CHART VERSION APP VERSION DESCRIPTION
elastic/elasticsearch 7.15.0 7.15.0 Official Elastic helm chart for Elasticsearch
elastic/eck-operator 1.8.0 1.8.0 A Helm chart for deploying the Elastic Cloud on...
elastic/eck-operator-crds 1.8.0 1.8.0 A Helm chart for installing the ECK operator Cu...

查询某个特定 Chart 版本

1
2
3
$ helm search repo elasticsearch --version "6.8.18"
NAME CHART VERSION APP VERSION DESCRIPTION
elastic/elasticsearch 6.8.18 6.8.18 Official Elastic helm chart for Elasticsearch

查询所有 Chart 版本。

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100

$ helm search repo elasticsearch --versions
NAME CHART VERSION APP VERSION DESCRIPTION
elastic/elasticsearch 7.15.0 7.15.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.14.0 7.14.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.4 7.13.4 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.3 7.13.3 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.2 7.13.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.1 7.13.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.0 7.13.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.12.1 7.12.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.12.0 7.12.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.11.2 7.11.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.11.1 7.11.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.10.2 7.10.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.10.1 7.10.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.10.0 7.10.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.9.3 7.9.3 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.9.2 7.9.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.9.1 7.9.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.9.0 7.9.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.8.1 7.8.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.8.0 7.8.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.7.1 7.7.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.7.0 7.7.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.6.2 7.6.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.6.1 7.6.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.6.0 7.6.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.5.2 7.5.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.5.1 7.5.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.5.0 7.5.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.4.1 7.4.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.4.0 7.4.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.3.2 7.3.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.3.0 7.3.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.2.0 7.2.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.1.1 7.1.1 Elasticsearch
elastic/elasticsearch 7.1.0 7.1.0 Elasticsearch
elastic/elasticsearch 6.8.18 6.8.18 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.17 6.8.17 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.16 6.8.16 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.15 6.8.15 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.14 6.8.14 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.13 6.8.13 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.12 6.8.12 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.11 6.8.11 Official Elastic helm chart for Elasticsearch
...

查询某个范围的Chart版本,以下要求Chart版本号大于等于1.0.0。

```bash

$ helm search repo elasticsearch --version ">=6.8.0" --versions
NAME CHART VERSION APP VERSION DESCRIPTION
elastic/elasticsearch 7.15.0 7.15.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.14.0 7.14.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.4 7.13.4 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.3 7.13.3 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.2 7.13.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.1 7.13.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.13.0 7.13.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.12.1 7.12.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.12.0 7.12.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.11.2 7.11.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.11.1 7.11.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.10.2 7.10.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.10.1 7.10.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.10.0 7.10.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.9.3 7.9.3 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.9.2 7.9.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.9.1 7.9.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.9.0 7.9.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.8.1 7.8.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.8.0 7.8.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.7.1 7.7.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.7.0 7.7.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.6.2 7.6.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.6.1 7.6.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.6.0 7.6.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.5.2 7.5.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.5.1 7.5.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.5.0 7.5.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.4.1 7.4.1 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.4.0 7.4.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.3.2 7.3.2 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.3.0 7.3.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.2.0 7.2.0 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 7.1.1 7.1.1 Elasticsearch
elastic/elasticsearch 7.1.0 7.1.0 Elasticsearch
elastic/elasticsearch 6.8.18 6.8.18 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.17 6.8.17 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.16 6.8.16 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.15 6.8.15 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.14 6.8.14 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.13 6.8.13 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.12 6.8.12 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.11 6.8.11 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.10 6.8.10 Official Elastic helm chart for Elasticsearch
elastic/elasticsearch 6.8.9 6.8.9 Official Elastic helm chart for Elasticsearch

6. helm pull

将 Chart 包下载到本地,缺省下载的是最新的 Chart 版本,并且是 tgz 包。

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
# 先查询Chart,选择一个合适的Chart。
$ helm search repo charts_name


# 拉取Chart包。
$ helm pull repo/chart_name

$ ls
name-version.tgz

# 可以解压Chart包。
tar zxvf name-version.tgz

# 拉取指定版本。
$ helm pull bitnami/tomcat --version 2.2.2
$ ls
tomcat-2.2.2.tgz

## 拉取Chart包后直接解压为目录,而不是tgz包。

$ helm pull bitnami/tomcat --untar
$ ls
tomcat

# 直接从URL下拉Chart包。
$ helm pull https://charts.helm.sh/stable/ambassador-5.3.1.tgz
$ ls
ambassador-5.3.1.tgz

# 拉取Chart包到指定路径。

$ helm pull stable/kong -d /root/helm/
$ ls /root/helm/
kong-0.36.6.tgz

7. helm install

安装应用,也就是部署一 Chart Release 实例。缺省安装最新 Chart 版本。其中 my-web 为 Release 名称,–set 配置会覆盖 Chart 的 values。Chart values 其它文档专门介绍。

有五种安装 Chart 的方式。

  1. Chart Reference:helm install myweb bitnami/tomcat

    Chart Reference 表示为[Repository]/[Chart],如 bitnami/tomcat,Helm 将在本地配置中查找名为 bitnami 的 Chart 仓库,然后在该仓库中查找名为 tomcat 的 Chart。

2.Chart 包路径:helm install myweb ./tomcat-6.1.3.tgz
3.Chart 包目录:helm install myweb ./tomcat
4.URL 绝对路径:helm install myweb https://charts.bitnami.com/bitnami/tomcat-6.1.3.tgz 5.仓库 URL 和 Chart Reference:helm install --repo https://charts.bitnami.com/bitnami/ myweb tomcat

安装特定 Chart 版本应用。

1
2

helm install myweb bitnami/tomcat --version 6.0.0

将应用安装到某一命名空间,不同的命名空间 Release 名称可以相同

1
2
3
4
5
6

kubectl create namespace web-ns

helm install myweb bitnami/tomcat -n web-ns

helm list -n web-ns

安装应用时,如果要覆盖 Chart 中的值,可以使用–set 选项并从命令行传递配置。若要强制–set 指定的值为字符串,请使用–set-string。–set 和–set-string 支持重复配置,后面(右边)的值优先级更高。

1
2
3
4
helm install myweb bitnami/tomcat \
--set service.type=NodePort \
--set persistence.enabled=false

1
2
3
4

# 也可以将key=values对配置在文件中,可以通过-f或者–values指定覆盖的values文件。-f或者–values支持重复指定,后面(右边)的值优先级更高。
$ helm install myweb bitnami/tomcat -f ./values.yaml

如果一个值很大或者占用多行,很难使用–values 或–set,可以使用–set-file 从文件中读取单个大值。

1
2
helm install myweb bitnami/tomcat \
--set-file podAnnotations=./tomcat-annotations.yaml

通过–dry-run 模拟安装应用,会输出每个模板生成的 yaml 内容,可查看将要部署的渲染后的 yaml,检视这些输出,判断是否与预期相符。

1
2
3
4
5

$ helm install my-web bitnami/tomcat \
--dry-run \
--set service.type=NodePort \
--set persistence.enabled=false

通过设置–wait 参数,将等待所有 Pod、PVC 和 Service 以及 Deployment、StatefulSet 和 ReplicaSet 的最小 Pod 数都处于就绪状态后,然后才将 Release 标记为 deployed 状态,然后 install 命令行返回成功。等待–timeout 时间,–timeout 缺省为 5m0s。

1
2
3
4
5

helm install myweb bitnami/tomcat \
--wait \
--set service.type=NodePort \
--set persistence.enabled=false

设置–timeout 参数,缺省为 5m0s。如果超过–timeout 还没有就绪,Release 状态将被标记为 failed,命令行返回值为 1,但并不会回退提交给 Kubernetes 的资源,所以安装不一定失败。如下载镜像时间过长,Release 的状态被置为 failed,但 Kubernetes 仍在会继续下载镜像,所以安装最终会成功,但 Release 不会被重置为 deployed。没有找到修改 Release 状态的命令。

1
2
3
4
5
6
7

设置–atomic参数,如果安装失败,会自动清除Chart,相当于如果状态为failed时会回退所有操作,保持安装的原子性。当设置–atomic参数时,–wait参数会自动配置。
helm install myweb bitnami/tomcat \
--atomic --timeout=1m \
--set service.type=NodePort \
--set persistence.enabled=false

8. helm list

列出 default 命名空间的 Release 列表,只显示状态为 deployed 或 failed 的 Release

1
2
3

helm list

列出某一命名空间的 Release 列表

1
2
3

helm list -n web-ns

列出所有命名空间的 Release 列表

1
2
3

helm list --all-namespaces

列出所有的 Release 列表,不止包括状态为 deployed 或 failed 的 Release

1
2
3

helm list -a

只列出所有状态为 deployed 的 Release 列表

1
2
3

helm list --deployed

只列出所有状态为 uninstalled 的 Release 列表

1
2
3

helm list --uninstalled

只列出所有状态为 failed 的 Release 列表。

1
2
3

helm list --failed

只列出所有状态为 pending-install 的 Release 列表。

1
2
3
4
5
6
7

# 在一个终端安装Chart,会花费一些时间。
$ helm install myweb-4 bitnami/tomcat \
--wait --timeout=10m \
--set service.type=NodePort \
--set persistence.enabled=false

在另一个终端执行如下命令,只列出正在安装的 Release

1
2
3

helm list --pending

按照时间顺序由早到晚列出 Release

1
2
3

helm list -d

按照时间顺序由晚到早列出 Release,-r 翻转排序。

1
2
3

helm list -d -r

9. helm uninstall

1
2
3
4
5
6
7
8
9
10

# 卸载应用,也就是删除Chart Release实例。
$ helm uninstall myweb

# 卸载某一命名空间的应用。
$ helm uninstall myweb -n web-ns

# 卸载应用,但保留历史记录,保留历史记录主要是为了回滚操作。
$ helm uninstall myweb --keep-history

10. helm test

Chart 包含了很多 Kubernetes 资源,而且根据 values。Helm 支持编写测试用例来验证 Chart 是否按预期工作。测试用例也有助于 Chart 使用者了解 Chart 应该做什么。

测试用例在 Helm Chart 中的 templates/目录,是一个 pod 定义,指定一个的命令来运行容器。容器应该成功退出(exit 0),测试被认为是成功的。该 pod 定义必须包含 helm 测试 hook 注释之一:helm.sh/hook: test-success 或 helm.sh/hook: test-failure。

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

helm install ambassador stable/ambassador \
--set authService.create=false \
--set rateLimit.create=false \
--set adminService.type=NodePort \
--set service.type=NodePort

helm pull stable/ambassador

# 查看测试用例pod,helm test执行就是该pod。
# 其实就是在容器执行命令:wget http://ambassador:80/ambassador/v0/check_ready
cat ambassador/templates/tests/test-ready.yaml
{{- if not .Values.daemonSet }}
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "ambassador.fullname" . }}-test-ready"
labels:
app.kubernetes.io/name: {{ include "ambassador.name" . }}
helm.sh/chart: {{ include "ambassador.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "ambassador.fullname" . }}:{{ include "ambassador.servicePort" . }}/ambassador/v0/check_ready']
restartPolicy: Never
{{- end }}

helm test ambassador
Pod ambassador-test-ready pending
Pod ambassador-test-ready pending
Pod ambassador-test-ready pending
Pod ambassador-test-ready succeeded
NAME: ambassador
LAST DEPLOYED: Wed Feb 12 12:56:51 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: ambassador-test-ready
Last Started: Wed Feb 12 13:10:24 2020
Last Completed: Wed Feb 12 13:10:42 2020
Phase: Succeeded
NOTES:
Congratulations! You've successfully installed Ambassador.

For help, visit our Slack at https://d6e.co/slack or view the documentation online at https://www.getambassador.io.

To get the IP address of Ambassador, run the following commands:
export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services ambassador)
export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT

测试时打印容器日志。

1
2
3

helm test ambassador --logs

11. helm status

1
2
3
4
5
6
7

# 显示Release的状态。
$ helm status myweb-2

# 显示Release的某个修订版本的状态。
$ helm status myweb-2 --revision 2

12. helm get

1
2
3
4
5
6
7

# 显示Release的所有的Kubernetes资源清单,注释标明了该资源生成于那个模板yaml文件。
$ helm get manifest myweb

# 显示Release的所涉及模板变量的值。
$ helm get all myweb --template {{.Release.Name}}

13. helm create

创建一个模板 Chart,会根据给定的 Chart 名称生成一个目录以及该 Chart 的一些样例文件。

我们可以使用 create 命令创建一个模板,然后根据该模板快速开发。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

helm create foo
Creating foo

ls
foo

tree foo
foo
├── charts
├── Chart.yaml
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── serviceaccount.yaml
│ ├── service.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml

3 directories, 9 files

14. helm show

显示 Chart 包的各种信息,Chart 包中的 Chart.yaml, values.yaml 和 README.md 文件包含了 Chart 重要关键信息,可以通过 helm show 命令行显示这些文件的内容,方便了解 Chart 关键内容。

显示 Chart.yaml 信息,该文件描述了 Chart 的版本,描述,开发者等信息。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24


helm show chart bitnami/tomcat
apiVersion: v1
appVersion: 9.0.30
description: Chart for Apache Tomcat
home: http://tomcat.apache.org
icon: https://bitnami.com/assets/stacks/tomcat/img/tomcat-stack-110x117.png
keywords:
- tomcat
- java
- http
- web
- application server
- jsp
maintainers:
- email: [email protected]
name: Bitnami
name: tomcat
sources:
- https://github.com/bitnami/bitnami-docker-tomcat
version: 6.1.3
---

显示 values.yaml 信息,该文件描述了 Chart 模板中各个可以覆盖的参数,这些参数都可以在安装 Chart 时被命令行参数覆盖。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

helm show values bitnami/tomcat
## Global Docker image parameters
## Please, note that this will override the image parameters, including dependencies, configured to use the global value
## Current available global Docker image parameters: imageRegistry and imagePullSecrets
##
# global:
# imageRegistry: myRegistryName
# imagePullSecrets:
# - myRegistryKeySecretName
# storageClass: myStorageClass

## Bitnami Tomcat image version
## ref: https://hub.docker.com/r/bitnami/tomcat/tags/
##
image:
registry: docker.io
repository: bitnami/tomcat
tag: 9.0.30-debian-9-r9

15. helm template

渲染 Chart 模板并打印输出,并不实际安装。和 helm get manifest 类似。

1
2
3
helm template myweb bitnami/tomcat \
--set service.type=NodePort \
--set persistence.enabled=false

16. helm dependency

1
2
3
4
5
6
7
8
9
10
11
12

# 管理Chart依赖。
helm dependency list

# 列出Chart申明的所有依赖的列表。
helm dependency update

# 更新Chart申明的所有依赖符合要求的最新版本,更新的依赖的tgz包文件会放到charts路径下。更新之前会先更新所有的仓库。
ls kong/charts/
postgresql
helm dependency update kong

17. helm lint

Helm 运行一系列测试以验证 Chart 格式是否正确。如果遇到会导致 Chart 安装失败的事件,将发出[ERROR]消息。如果遇到违反约定或推荐的问题,将发出[WARNING]消息。

1
2
3
4
helm lint tomcat/
==> Linting tomcat/

1 chart(s) linted, 0 chart(s) failed

18. helm package

将目录结构的 Chart 打包成带版本号 tgz 格式的 Chart 包。和 helm repo index 配合用来搭建私有仓库。

1
2
3
4
5
6
7
8
9
10
helm pull bitnami/tomcat --untar --version 6.1.6

ls
tomcat

helm package tomcat
Successfully packaged chart and saved it to: /root/helm/tomcat-6.1.6.tgz

ls
tomcat tomcat-6.1.6.tgz

在打包时,设置覆盖的 values,此时 Chart 包中 values.yaml 文件对应的 key 的键值会被自动替换为命令行中的 values。

1
2
3
helm package tomcat \
--set service.type=NodePort \
--set persistence.enabled=false

19. 参考文档

Helm 最详细的命令大全

helm v3 使用指南|常见命令行(2)

作者

鹏叔

发布于

2024-09-03

更新于

2024-09-04

许可协议

评论