Kubernetes实战总结 - Helm新旧版本部署

什么是Helm?

Helm 是 Kubernetes 的软件包管理器,用来简化 Kubernetes 应用的部署和管理。

Helm 和 Kubernetes 的关系,就好比 yum 和 CentOS,apt-get 和 Ubuntu 的关系。

Helm2 主要分为客户端 helm 和服务端 tiller,但最新发行 Helm3 已经移除了 tiller。

Helm
Helm 是一个命令行下的客户端工具。主要用于 Kubernetes 应用程序 Chart 的创建、打包、发布以及创建和管理本地和远程的 Chart 仓库。

Tiller
Tiller 是 Helm 的服务端,部署在 Kubernetes 集群中。Tiller 用于接收 Helm 的请求,并根据 Chart 生成 Kubernetes 的部署文件( Helm 称为 Release ),然后提交给 Kubernetes 创建应用。Tiller 还提供了 Release 的升级、删除、回滚等一系列功能。

Chart
包含了创建Kubernetes的一个应用实例的必要信息,Helm 的软件包,采用 TAR 格式。类似于 APT 的 DEB 包或者 YUM 的 RPM 包,其包含了一组定义 Kubernetes 资源相关的 YAML 文件。

Repoistory
Helm 的软件仓库,Repository 本质上是一个 Web 服务器,该服务器保存了一系列的 Chart 软件包以供用户下载,并且提供了一个该 Repository 的 Chart 包的清单文件以供查询。Helm 可以同时管理多个不同的 Repository。

Release
是一个 chart 及其配置的一个运行实例,使用 helm install 命令在 Kubernetes 集群中部署的 Chart 称为 Release。
Helm主要概念说明

注意:虽然helm比较好用,但新手不建议使用,因为快捷的部署管理不利于你对应用结构的理解。当然,如果你只是短期使用,不追求深层的掌握,helm是个不错的选择。


怎么安装Helm2?

官方地址:https://helm.sh/docs/intro/install/,其中介绍了很多种部署方式,最常用的就是二进制方式。

使用二进制方式,首先下载 helm-v2.16.3-linux-amd64.tar.gz,执行以下命令。

tar -zxvf helm-v2.16.3-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm
chmod a+x /usr/local/bin/helm 

最后我们还需要安装服务端tiller,首先创建rbac访问控制yaml文件。

# tiller-rbac.yaml

apiVersion: v1 kind: ServiceAccount metadata: name: tiller namespace: kube
-system --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: tiller roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: tiller namespace: kube-system

然后执行命令部署,初始化。

kubectl apply -f tiller-rbac.yaml
helm init --service-account tiller --skip-refresh

因为默认使用的grc.io库,如果网络不好,可以更改镜像源(这是我的阿里云镜像地址,版本有限,部署其他版本请自行搜索更换)。

kubectl -n kube-system set image deployment/tiller-deploy tiller=registry.cn-shanghai.aliyuncs.com/leozhanggg/helm/tiller:v2.16.3

最后验证是否部署成功。 

helm version
Client: &version.Version{SemVer:"v2.16.3", GitCommit:"1ee0254c86d4ed6887327dabed7aa7da29d7eb0d", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.16.3", GitCommit:"1ee0254c86d4ed6887327dabed7aa7da29d7eb0d", GitTreeState:"clean"}

如果你还是觉得有点麻烦,我们可以编写shell脚本,把整个流程串起来:

#!/bin/sh
# creator: zhangfan
# up-date: 2020/04/10
# description: one key deploy.

tag="v2.16.3"
helm_path="/usr/local/bin"
tiller_image="registry.cn-shanghai.aliyuncs.com/leozhanggg/helm/tiller:${tag}"

echo "Intall helm to ${helm_path}"
cp helm ${helm_path}
chmod a+x ${helm_path}/helm
echo

echo "helm init..."
kubectl apply -f tiller-rbac.yaml
helm init --service-account tiller --skip-refresh
sleep 3
echo

echo "set image to ${tiller_image}"
kubectl -n kube-system set image deployment/tiller-deploy tiller=${tiller_image}
until helm version 2>/dev/null ; do 
  echo "Warning: Waiting for completion or termination."
  echo
  sleep 5
done

echo "Successfully deployed!!!"

 这样我们只需要创建文件install.sh和rbac.yaml,然后放到Helm-2.16.3版本内执行脚本就可以了。

[root@k8s-32 helm-2.16.3]# ls
install.sh helm LICENSE README.md tiller tiller-rbac.yaml
[root@k8s-32 helm-2.16.3]# sh install.sh
Intall helm to /usr/local/bin

helm init...
serviceaccount/tiller created
clusterrolebinding.rbac.authorization.k8s.io/tiller created
$HELM_HOME has been configured at /root/.helm.
Warning: Tiller is already installed in the cluster.
(Use --client-only to suppress this message, or --upgrade to upgrade Tiller to the current version.)

set image to registry.cn-shanghai.aliyuncs.com/leozhanggg/helm/tiller:v2.16.3
deployment.apps/tiller-deploy image updated
Client: &version.Version{SemVer:"v2.16.3", GitCommit:"1ee0254c86d4ed6887327dabed7aa7da29d7eb0d", GitTreeState:"clean"}
Warning: Waiting for completion or termination.

Client: &version.Version{SemVer:"v2.16.3", GitCommit:"1ee0254c86d4ed6887327dabed7aa7da29d7eb0d", GitTreeState:"clean"}
Warning: Waiting for completion or termination.

Client: &version.Version{SemVer:"v2.16.3", GitCommit:"1ee0254c86d4ed6887327dabed7aa7da29d7eb0d", GitTreeState:"clean"}
Warning: Waiting for completion or termination.

Client: &version.Version{SemVer:"v2.16.3", GitCommit:"1ee0254c86d4ed6887327dabed7aa7da29d7eb0d", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.16.3", GitCommit:"1ee0254c86d4ed6887327dabed7aa7da29d7eb0d", GitTreeState:"clean"}
Successfully deployed!!!

怎么安装Helm3?

由于helm3移除了tiller,所以安装起来就很简单了,直接使用二进制方式,首先下载版本 helm-v3.1.1-linux-amd64.tar.gz,然后执行以下命令即可。

tar -zxvf helm-v3.1.1-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm
chmod a+x /usr/local/bin/helm 

helm version
version.BuildInfo{Version:"v3.1.1", GitCommit:"afe70585407b420d0097d07b21c47dc511525ac8", GitTreeState:"clean", GoVersion:"go1.13.8"}

其他

  【问题一】Error: error installing: the server could not find the requested resource

    问题回顾:kubernetes-1.17.4集群,安装helm-2.13.1,进行helm init报错

    解决方案:这是由于版本兼容性问题,安装较新的版本helm-2.16.3问题解决

猜你喜欢

转载自www.cnblogs.com/leozhanggg/p/12679869.html
今日推荐