Fork me on GitHub

Helm简介和安装部署

目录

  • 背景
  • 第一部分 Minikube集群启动
  • 第一部分 Kubernetes中StatefulSet介绍
  • 第三部分 部署Zookeeper集群
  • 第四部分 部署Kafka集群
  • 第五部分 总结
  • 参考文献及资料

背景

Helm 是 Kubernetes 的软件包管理工具(Application deployment management for Kubernetes)。

通常我们在k8s集群中部署一个可以使用的应用,一般会涉及多个组件资源的共同协作。例如需要安装部署一个web应用,包括 Deployment 用于部署应用、Service 提供服务发现、Secret 配置 应用的用户名和密码,可能还需要 pv 和 pvc 来提供持久化服务。web应用的后台数据是存储在mysql里面的,所以需要 mysql启动就绪后才能启动 web前台。涉及的资源较多还有前后项编排等管理,如果只是通过kubectl管理,这是一个复杂辛苦的工作。

helm的出现就是解决上面的痛点。主要解决的问题有:

  • 统一管理、配置和更新应用资源文件;
  • 分发和服用应用模板;
  • 将应用的一系列资源整体作为一个软件包管理;

第一部分 Helm的部署

Helm是由helm CLI和Tiller组成,即典型的C/S应用。helm运行与客户端,提供命令行界面,而Tiller应用运行在Kubernetes内部。

  • helm 是一个命令行工具,用于本地开发及管理chart,chart仓库管理等;
  • Tiller 是 Helm 的服务端。Tiller 负责接收 Helm 的请求,与 k8s 的 apiserver 交互,根据chart 来生成一个 release 并管理 release;
  • chart Helm的打包格式叫做chart,所谓chart就是一系列文件, 它描述了一组相关的 k8s 集群资源;
  • release 使用 helm install 命令在 Kubernetes 集群中部署的 Chart 称为 Release;
  • Repoistory Helm chart 的仓库,Helm 客户端通过 HTTP 协议来访问存储库中 chart 的索引文件和压缩包;

1.1 部署Helm CLI客户端

helm客户端是一个单纯的可执行文件,我们从github上直接下载压缩包(由于墙的原因可能很慢):

1
root@deeplearning:/data/helm# wget https://get.helm.sh/helm-v2.14.3-linux-amd64.tar.gz

解压缩介质文件:

1
2
3
4
5
6
root@deeplearning:/data/helm# tar -zxvf helm-v2.14.3-linux-amd64.tar.gz 
linux-amd64/
linux-amd64/helm
linux-amd64/README.md
linux-amd64/LICENSE
linux-amd64/tiller

部署:

1
root@deeplearning:/data/helm# mv linux-amd64/helm /usr/local/bin

检查:

1
2
3
root@deeplearning:/data/helm# helm version
Client: &version.Version{SemVer:"v2.14.3", GitCommit:"0e7f3b6637f7af8fcfddb3d2941fcc7cbebb0085", GitTreeState:"clean"}
Error: could not find tiller

提示未连接到服务端tiller。下面我们部署服务端。

1.2 部署服务端

Helm 的服务器端部分 Tiller 通常运行在 Kubernetes 集群内部。但是对于开发,它也可以在本地运行,并配置为与远程 Kubernetes 群集通信。

安装 tiller 到群集中最简单的方法就是运行 helm init。这将验证 helm 本地环境设置是否正确(并在必要时进行设置)。然后它会连接到 kubectl 默认连接的任何集群(kubectl config view)。一旦连接,它将安装 tillerkube-system 命名空间中。

helm init 以后,可以运行 kubectl get pods --namespace kube-system 并看到 Tiller 正在运行。

你可以通过参数运行 helm init:

  • --canary-image 参数安装金丝雀版本
  • --tiller-image 安装特定的镜像(版本)
  • --kube-context 使用安装到特定群集
  • --tiller-namespace 用一个特定的命名空间 (namespace) 安装
  • --service-account 使用 Service Account 安装 RBAC enabled clusters
  • --automount-service-account false 不适用 service account 安装

一旦安装了 Tiller,运行 helm version 会显示客户端和服务器版本。(如果它仅显示客户端版本, helm 则无法连接到服务器, 使用 kubectl 查看是否有任何 tiller Pod 正在运行。)

除非设置 --tiller-namespaceTILLER_NAMESPACE 参数,否则 Helm 将在命名空间 kube-system 中查找 Tiller 。

在缺省配置下, Helm 会利用 “gcr.io/kubernetes-helm/tiller“ 镜像在Kubernetes集群上安装配置 Tiller;并且利用 “https://kubernetes-charts.storage.googleapis.com“ 作为缺省的 stable repository 的地址。由于在国内可能无法访问 “gcr.io“, “storage.googleapis.com“ 等域名,阿里云容器服务为此提供了镜像站点。

首先创建服务。创建rbac-config.yaml文件,文件内容为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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

通过yaml文件创建服务:

1
2
3
root@deeplearning:/data/helm# kubectl create -f rbac-config.yaml
serviceaccount/tiller created
clusterrolebinding.rbac.authorization.k8s.io/tiller created

启Helm pod,即安装tiller:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
root@deeplearning:/data/helm#helm init -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v3.0.2 \
--stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts \
--service-account tiller
# 回显
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.oss-cn-hangzhou.aliyuncs.com/charts
Adding local repo with URL: http://127.0.0.1:8879/charts
$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.)

这时候我们再次执行:

1
2
3
root@deeplearning:/data/helm# helm version
Client: &version.Version{SemVer:"v2.14.3", GitCommit:"0e7f3b6637f7af8fcfddb3d2941fcc7cbebb0085", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.10.0", GitCommit:"9ad53aac42165a5fadc6c87be0dea6b115f93090", GitTreeState:"clean"}

这样Helm的服务端tiller就部署完毕。

1.3 Helm CLI 命令简要汇总

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
// 安装一个 Chart
helm install stable/mysql

// 列出 Kubernetes 中已部署的 Chart
helm list --all

// helm repo 的操作
helm repo update
helm repo list
helm repo add dev https://example.com/dev-charts

// 创建一个 Chart,会产生一个 Chart 所需的目录结构
helm create deis-workflow

// 安装自定义 chart
helm inspect values stable/mysql # 列出一个 chart 的可配置项

helm install -f config.yaml stable/mysql # 可以将修改的配置项写到文件中通过 -f 指定并替换
helm install --set name: value stable/mysql # 也可以通过 --set 方式替换

// 当新版本 chart 发布时,或者当你需要更改 release 配置时,helm 必须根据现在已有的 release 进行升级
helm upgrade -f panda.yaml happy-panda stable/mariadb

// 删除 release
helm delete happy-panda

参考文献及材料

1、Helm User Guide - Helm 用户指南 https://whmzsu.github.io/helm-doc-zh-cn/

2、Kubernetes 包管理工具 Helm 简介 https://www.jianshu.com/p/d55e91e28f94

3、Helm介绍 https://zhaohuabing.com/2018/04/16/using-helm-to-deploy-to-kubernetes/

本文标题:Helm简介和安装部署

文章作者:rong xiang

发布时间:2019年08月08日 - 21:08

最后更新:2022年10月25日 - 23:10

原始链接:https://zjrongxiang.github.io/posts/c147e1bc/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

0%