这篇文章搭建一下Helm 2和Helm 3使用的集群环境,并在其中分别安装Helm 2和Helm 3,然后通过比较Helm 2和Helm 3下初始化操作的方式,从而更好的了解其不同之处。
[root@liumiaocn ~]# uname -a
Linux liumiaocn 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[root@liumiaocn ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@liumiaocn ~]#
[root@liumiaocn ~]# helm version
version.BuildInfo{Version:"v3.0.0", GitCommit:"e29ce2a54e96cd02ccfce88bee4f58bb6e2a28b6", GitTreeState:"clean", GoVersion:"go1.13.4"}
[root@liumiaocn ~]#
安装方法可参看:https://liumiaocn.blog.csdn.net/article/details/103360312
[root@liumiaocn ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3-k3s.2", GitCommit:"e7e6a3c4e9a7d80b87793612730d10a863a25980", GitTreeState:"clean", BuildDate:"2019-11-18T18:31:23Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3-k3s.2", GitCommit:"e7e6a3c4e9a7d80b87793612730d10a863a25980", GitTreeState:"clean", BuildDate:"2019-11-18T18:31:23Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
[root@liumiaocn ~]#
liumiao $ cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.2 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.2 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
liumiao $ helm version
Client: &version.Version{SemVer:"v2.8.2", GitCommit:"a80231648a1473929271764b920a8e346f6de844", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.8.2", GitCommit:"a80231648a1473929271764b920a8e346f6de844", GitTreeState:"clean"}
liumiao $
liumiao $ kubectl version
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.0", GitCommit:"641856db18352033a0d96dbc99153fa3b27298e5", GitTreeState:"clean", BuildDate:"2019-03-25T15:53:57Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.0", GitCommit:"641856db18352033a0d96dbc99153fa3b27298e5", GitTreeState:"clean", BuildDate:"2019-03-25T15:45:25Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}
liumiao $
Helm 2和Helm 3最大的区别是什么?Tiller,首先来看一下Helm 2的基本构成:
在Helm 2的时代,Helm是由两个东西构成:
在早期的Helm 2版本中,是有helm和tiller两个二进制文件的,而Helm 3只有一个。虽然在诸如Helm 2.8.2的版本中只有一个二进制文件,Helm 2中还是存在初始化操作的这条命令的,使用helm init命令时还是能够非常清楚地看到tiller的存在的。
liumiao $ ls
liumiao $ pwd
/root/helm2test
liumiao $ ls
liumiao $ helm init
Creating /root/.helm
Creating /root/.helm/repository
Creating /root/.helm/repository/cache
Creating /root/.helm/repository/local
Creating /root/.helm/plugins
Creating /root/.helm/starters
Creating /root/.helm/cache/archive
Creating /root/.helm/repository/repositories.yaml
Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com
Adding local repo with URL: http://127.0.0.1:8879/charts
$HELM_HOME has been configured at /root/.helm.
Tiller (the Helm server-side component) has been installed into your Kubernetes Cluster.
Please note: by default, Tiller is deployed with an insecure 'allow unauthenticated users' policy.
For more information on securing your installation see: https://docs.helm.sh/using_helm/#securing-your-helm-installation
Happy Helming!
liumiao $ ls
liumiao $ ls /root/.helm/
cache plugins repository starters
liumiao $
实际上初始化最重要的内容之一就是设定repository,在helm init的命令之中我们也可以看到添加repository的日志信息。使用helm repo list命令来进行确认
liumiao $ helm repo list
NAME URL
stable https://kubernetes-charts.storage.googleapis.com
local http://127.0.0.1:8879/charts
liumiao $
另外Helm 2在helm init之后一般会使用helm repo update命令,这样像helm version等命令才能更好地运行。接下来就可以使用helm search命令搜索mysql相关的chart了。
liumiao $ helm search mysql
NAME CHART VERSION APP VERSION DESCRIPTION
stable/mysql 1.4.0 5.7.27 Fast, reliable, scalable, and easy to use open-...
stable/mysqldump 2.6.0 2.4.1 A Helm chart to help backup MySQL databases usi...
stable/prometheus-mysql-exporter 0.5.2 v0.11.0 A Helm chart for prometheus mysql exporter with...
stable/percona 1.2.0 5.7.17 free, fully compatible,enhanced, open source d...
stable/percona-xtradb-cluster 1.0.3 5.7.19 free, fully compatible,enhanced, open source d...
stable/phpmyadmin 4.2.4 4.9.2 phpMyAdmin is an mysql administration frontend
stable/gcloud-sqlproxy 0.6.1 1.11 DEPRECATED Google CloudSQL Proxy
stable/mariadb 7.2.1 10.3.20 Fast, reliable, scalable, and easy to use open-...
liumiao $
[root@liumiaocn ~]# helm env
HELM_PLUGINS="/root/.local/share/helm/plugins"
HELM_REGISTRY_CONFIG="/root/.config/helm/registry.json"
HELM_REPOSITORY_CACHE="/root/.cache/helm/repository"
HELM_REPOSITORY_CONFIG="/root/.config/helm/repositories.yaml"
HELM_NAMESPACE="default"
HELM_KUBECONTEXT=""
HELM_BIN="helm"
HELM_DEBUG="false"
[root@liumiaocn ~]#
确认一下当前的repository,提示了一个错误信息,实际上是因为还没有设定。
[root@liumiaocn ~]# helm repo list
Error: no repositories to show
[root@liumiaocn ~]# echo $?
1
[root@liumiaocn ~]#
而在Helm 2中如果不使用helm init命令直接进行helm repo list的情况下,同样会提示出错信息,示例信息如下所示:
Error: Couldn't load repositories file (/root/.helm/repository/repositories.yaml).
You might need to run `helm init` (or `helm init --client-only` if tiller is already installed)
通过helm repo add命令我们添加https://kubernetes-charts.storage.googleapis.com作为repository。
[root@liumiaocn ~]# helm repo add stable https://kubernetes-charts.storage.googleapis.com
"stable" has been added to your repositories
[root@liumiaocn ~]# helm repo list
NAME URL
stable https://kubernetes-charts.storage.googleapis.com
[root@liumiaocn ~]#
在Helm 3中增强了search的功能,作为代价,直接使用helm search mysql无法进行搜索了,需要指定repo,执行示例日志如下所示:
[root@liumiaocn ~]# helm search repo mysql
NAME CHART VERSION APP VERSION DESCRIPTION
stable/mysql 1.4.0 5.7.27 Fast, reliable, scalable, and easy to use open-...
stable/mysqldump 2.6.0 2.4.1 A Helm chart to help backup MySQL databases usi...
stable/prometheus-mysql-exporter 0.5.2 v0.11.0 A Helm chart for prometheus mysql exporter with...
stable/percona 1.2.0 5.7.17 free, fully compatible, enhanced, open source d...
stable/percona-xtradb-cluster 1.0.3 5.7.19 free, fully compatible, enhanced, open source d...
stable/phpmyadmin 4.2.4 4.9.2 phpMyAdmin is an mysql administration frontend
stable/gcloud-sqlproxy 0.6.1 1.11 DEPRECATED Google Cloud SQL Proxy
stable/mariadb 7.2.1 10.3.20 Fast, reliable, scalable, and easy to use open-...
[root@liumiaocn ~]#