轻松完爆 Helm release

一、release介绍

在以上的章节中曾介绍过 helm 的两大术语:chart 和 release。如果可以把 chart 比作程序源码的话,那么 release 则可以看做是程序运行时的进程。

chart 是用户可直接感知的对象(其表现形式就是 .tgz 格式的压缩包);而 release 理解起来则比较抽象,它是专属于 helm 的一个逻辑概念,用来标识在 k8s 中运行的一组资源。有了 release,helm 在操作 k8s 时,就再也不用逐个管理资源,而可以将一组相关的资源当做一个整体来操作,比如删除或升级。

二、release 查看

$ helm ls
NAME    NAMESPACE       REVISION        UPDATED STATUS  CHART   APP VERSION

三、release 安装

在线安装指定的 chart,比如 nginx-ingress。

$ helm repo add nginx-stable https://helm.nginx.com/stable
$ helm repo update

$ helm search repo nginx-ingress
NAME                            CHART VERSION   APP VERSION     DESCRIPTION
aliyun/nginx-ingress            0.9.5           0.10.2          An nginx Ingress controller that uses ConfigMap...
nginx-stable/nginx-ingress      0.9.3           1.11.3          NGINX Ingress Controller
stable/nginx-ingress            1.41.3          v0.34.1         DEPRECATED! An nginx Ingress controller that us...
aliyun/nginx-lego               0.3.1                           Chart for nginx-ingress-controller and kube-lego
stable/nginx-lego               0.3.1                           Chart for nginx-ingress-controller and kube-lego

$ helm install mynginx-ingress nginx-stable/nginx-ingress
NAME: mynginx-ingress
LAST DEPLOYED: Sat Jun 12 16:17:57 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
The NGINX Ingress Controller has been installed.

四、release更新

如果想修改运行时 release 的配置,可以使用 --set 或者 -f 选项进行修改。

4.1 基于命令行更新 release

# mynginx-ingress 是上面创建的 release 名;nginx-stable/nginx-ingress 是在线 chart 名

$ helm upgrade --set controller.hostNetwork=true mynginx-ingress nginx-stable/nginx-ingress
Release "mynginx-ingress" has been upgraded. Happy Helming!
NAME: mynginx-ingress
LAST DEPLOYED: Sat Jun 12 16:20:05 2021
NAMESPACE: default
STATUS: deployed
REVISION: 2
TEST SUITE: None
NOTES:
The NGINX Ingress Controller has been installed.

4.2 基于文件更新 release

如果想基于文件来更新 release,则首先需要将 chart 下载到本地,然后手动修改 chart 的 values.yaml 文件。

$ helm pull nginx-stable/nginx-ingress
# 下载 chart

$ tar zxf nginx-ingress-0.9.3.tgz
# 解压缩 chart

$ sed -i 's/hostNetwork: false/hostNetwork: true/g' nginx-ingress/values.yaml
# 修改 values.yaml 内容。比如修改 hostNetwork 的值为 true

$ helm upgrade mynginx-ingress nginx-ingress -f nginx-ingress/values.yaml
Release "mynginx-ingress" has been upgraded. Happy Helming!
NAME: mynginx-ingress
LAST DEPLOYED: Sat Jun 12 16:23:50 2021
NAMESPACE: default
STATUS: deployed
REVISION: 3
TEST SUITE: None
NOTES:
The NGINX Ingress Controller has been installed.

4.3 查看 release 更新后的新值

$ helm get values mynginx-ingress

五、release 版本

$ helm history mynginx-ingress
# mynginx-ingress 这个 release 各个历史版本。其中 REVISION 3 是最新的版本。
REVISION        UPDATED                         STATUS          CHART                   APP VERSION     DESCRIPTION
1               Sat Jun 12 16:17:57 2021        superseded      nginx-ingress-0.9.3     1.11.3          Install complete
2               Sat Jun 12 16:20:05 2021        superseded      nginx-ingress-0.9.3     1.11.3          Upgrade complete
3               Sat Jun 12 16:23:50 2021        deployed        nginx-ingress-0.9.3     1.11.3          Upgrade complete

六、release 回滚

$ helm rollback mynginx-ingress 1
Rollback was a success! Happy Helming!

$ helm history mynginx-ingress
REVISION        UPDATED                         STATUS          CHART                   APP VERSION     DESCRIPTION
1               Sat Jun 12 16:17:57 2021        superseded      nginx-ingress-0.9.3     1.11.3          Install complete
2               Sat Jun 12 16:20:05 2021        superseded      nginx-ingress-0.9.3     1.11.3          Upgrade complete
3               Sat Jun 12 16:23:50 2021        superseded      nginx-ingress-0.9.3     1.11.3          Upgrade complete
4               Sat Jun 12 16:29:59 2021        deployed        nginx-ingress-0.9.3     1.11.3          Rollback to 1

七、release 卸载

$ helm uninstall mynginx-ingress
release "mynginx-ingress" uninstalled
posted @ 2021-06-12 16:33  吕振江  阅读(2444)  评论(0编辑  收藏  举报
浏览器标题切换
浏览器标题切换end