Helm - Kubernetes包管理专家
What is Helm?
- The package manager for kubernetes, Helm is the best way to find, share, and use software built for kubernetes.
Helm helps you manage Kubernetes applications — Helm Charts helps you define, install, and upgrade even the most complex Kubernetes application.
Charts are easy to create, version, share, and publish — so start using Helm and stop the copy-and-paste madness.
The latest version of Helm is maintained by the CNCF - in collaboration with Microsoft, Google, Bitnami and the Helm contributor community.
Why use Helm?
kubernetes发布一个生产级别的微服务应用需要包含的内容;当环境中的微服务越来越多,单纯通过手工的方式去管理将会非常混乱和负载。这时候Helm就应该登场了。
Helm Architecture
上面这张图描述了Helm的几个关键组件Helm(客户端),Tiller(服务器),Repository(Chart软件仓库),Release(Chart运行的实例),Chart(软件包)之前的关系。
重要概念
Helm 有三个重要概念:
- chart:包含了创建
Kubernetes
的一个应用实例的必要信息 - config:包含了应用发布配置信息
- release:是一个 chart 及其配置的一个运行实例
Helm组件
Helm 有以下两个组成部分:
Helm Client
是用户命令行工具,其主要负责如下:
- 本地 chart 开发
- 仓库管理
- 与 Tiller sever 交互
- 发送预安装的 chart
- 查询 release 信息
- 要求升级或卸载已存在的 release
Tiller Server
是一个部署在Kubernetes
集群内部的 server,其与 Helm client、Kubernetes API server 进行交互。
Tiller server 主要负责如下:
- 监听来自 Helm client 的请求
- 通过 chart 及其配置构建一次发布
- 安装 chart 到
Kubernetes
集群,并跟踪随后的发布 - 通过与
Kubernetes
交互升级或卸载 chart - 简单的说,client 管理 charts,而 server 管理发布 release
Helm部署方法(1)
在其中一个K8S节点上安装Helm Client(需要配置代理,否则无法下载安装包)
$ curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 6737 100 6737 0 0 3204 0 0:00:02 0:00:02 --:--:-- 3205 Downloading https://kubernetes-helm.storage.googleapis.com/helm-v2.9.0-linux-amd64.tar.gz Preparing to install into /usr/local/bin helm installed into /usr/local/bin/helm Run 'helm init' to configure helm.
Tiller 服务器安装非常简单,只需要执行 helm init(需要配置docker代理,否则Tiller Image无法从gcr.io下载)
$ 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!
验证
$ helm version Client: &version.Version{SemVer:"v2.9.0", GitCommit:"f6025bb9ee7daf9fee0026541c90a6f557a3e0bc", GitTreeState:"clean"} Server: &version.Version{SemVer:"v2.9.0", GitCommit:"f6025bb9ee7daf9fee0026541c90a6f557a3e0bc", GitTreeState:"clean"}
配置RBAC
我的kubernetes 集群是1.10版本的,默认开启了RBAC
访问控制,所以我们需要为Tiller
创建一个ServiceAccount
,让他拥有执行的权限,详细内容可以查看 Helm 文档中的Role-based Access Control。
kubectl create serviceaccount --namespace kube-system tiller kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
问题
部署完成后,发现无法install任何chart,查看tiller容器的的logs发现以下错误日志,google查询到是2.9的bug,降级到2.8.2即可。
Helm部署方法(2)
安装Helm Client,
直接在Helm Realese页面下载二进制文件,这里下载的2.8.2版本,解压后将可执行文件helm
拷贝到/usr/local/bin
目录下即可,这样Helm
客户端就在这台机器上安装完成了。
$ helm version Client: &version.Version{SemVer:"v2.8.2", GitCommit:"a80231648a1473929271764b920a8e346f6de844", GitTreeState:"clean"}
安装Helm Server,
执行命令
$ helm init
由于 Helm 默认会去gcr.io
拉取镜像,所以如果你当前执行的机器没有配置科学上网的话可以实现下面的命令代替:
$ helm init --upgrade --tiller-image cnych/tiller:v2.8.2
创建Tiller ServiceAccount
kubectl create serviceaccount --namespace kube-system tiller kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
查看结果
$ helm version Client: &version.Version{SemVer:"v2.8.2", GitCommit:"a80231648a1473929271764b920a8e346f6de844", GitTreeState:"clean"} Server: &version.Version{SemVer:"v2.8.2", GitCommit:"a80231648a1473929271764b920a8e346f6de844", GitTreeState:"clean"}
$ helm list
参考文档:
https://helm.sh/
https://blog.qikqiak.com/post/first-use-helm-on-kubernetes/