Helm 致力于成为 Kubernetes 的包管理工具,可以方便地发现、共享和使用为 Kubernetes 构建的应用,它包含几个基本概念:
Helm 采用客户端/服务器架构,有如下组件组成:
Helm工作原理:
Helm把Kubernetes资源(比如deployments、services或 ingress等) 打包到一个chart中,而chart被保存到chart仓库。通过chart仓库可用来存储和分享chart。Helm使发布可配置,支持发布应用配置的版本管理,简化了Kubernetes部署应用的版本控制、打包、发布、删除、更新等操作
Helm客户端:
Helm客户端是一个命令行工具,负责管理charts、reprepository和release。它通过gPRC API(使用kubectl port-forward将tiller的端口映射到本地,然后再通过映射后的端口跟tiller通信)向tiller发送请求,并由tiller来管理对应的Kubernetes资源
Tiller服务端:
Tiller接收来自Helm客户端的请求,并把相关资源的操作发送到Kubernetes,负责管理(安装、查询、升级或删除等)和跟踪Kubernetes资源。为了方便管理,tiller把release的相关信息保存在kubernetes的ConfigMap中
从官网下载最新版本的二进制安装包到本地:https://github.com/kubernetes/helm/releases
解压安装:
# 解压压缩包
tar -zxvf helm-2.9.0.tar.gz
# 把 helm 指令放到bin目录下
mv helm-2.9.0/helm /usr/local/bin/helm
# 验证
helm help
在 Kubernetes 中安装 Tiller 服务,可选镜像:registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.9.1(阿里云)
1)先在 K8S 集群上每个节点安装 socat 软件,不然会报如下错误:
E0522 22:22:15.492436 24409 portforward.go:331] an error occurred forwarding 38398 -> 44134: error forwarding port 44134 to pod dc6da4ab99ad9c497c0cef1776b9dd18e0a612d507e2746ed63d36ef40f30174, uid : unable to do port forwarding: socat not found.
Error: cannot connect to Tiller
# YUM 安装(每个节点都要安装)
yum install -y socat
2)安装服务端(Tiller)
# 创建服务端
helm init --service-account tiller --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.9.1 --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
# 创建TLS认证服务端,参考地址:https://github.com/gjmzj/kubeasz/blob/master/docs/guide/helm.md
helm init --service-account tiller --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.9.1 --tiller-tls-cert /etc/kubernetes/ssl/tiller001.pem --tiller-tls-key /etc/kubernetes/ssl/tiller001-key.pem --tls-ca-cert /etc/kubernetes/ssl/ca.pem --tiller-namespace kube-system --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
遇到错误 failed to list: configmaps is forbidden: User “system:serviceaccount:kube-system:default” cannot list configmaps in the namespace “kube-system”
执行以下命令创建 serviceaccount tiller 并且给它集群管理权限
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 版本信息
helm version
Client: &version.Version{SemVer:"v2.9.1", GitCommit:"20adb27c7c5868466912eebdf6664e7390ebe710", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.9.1", GitCommit:"20adb27c7c5868466912eebdf6664e7390ebe710", GitTreeState:"clean"}
# 查看 pod 运行情况
kubectl get pod -o wide --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE
kube-system tiller-deploy-59c7578f9b-28kb9 1/1 Running 0 16s 172.20.0.41 192.168.80.231
1)更换仓库:
若遇到Unable to get an update from the “stable” chart repository (https://kubernetes-charts.storage.googleapis.com) 错误
手动更换stable 存储库为阿里云的存储库
# 先移除原先的仓库
helm repo remove stable
# 添加新的仓库地址
helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
# 更新仓库
helm repo update
2)查看在存储库中可用的所有 Helm charts:
helm search
NAME CHART VERSION APP VERSION DESCRIPTION
stable/acs-engine-autoscaler 2.1.3 2.1.1 Scales worker nodes within agent pools
stable/aerospike 0.1.7 v3.14.1.2 A Helm chart for Aerospike in Kubernetes
stable/anchore-engine 0.1.3 0.1.6 Anchore container analysis and policy evaluatio...
stable/artifactory 7.0.3 5.8.4 Universal Repository Manager supporting all maj...
stable/artifactory-ha 0.1.0 5.8.4 Universal Repository Manager supporting all maj...
stable/aws-cluster-autoscaler 0.3.2 Scales worker nodes within autoscaling groups.
... ...
3)更新charts列表:
helm repo update
4)安装charts:
Monocular是一个开源软件,用于管理kubernetes上以Helm Charts形式创建的服务,可以通过它的web页面来安装helm Charts
安装Nginx Ingress controller,安装的k8s集群启用了RBAC,则一定要加rbac.create=true参数
helm install stable/nginx-ingress --set controller.hostNetwork=true,rbac.create=true
安装Monocular:
# 添加新的源
helm repo add monocular https://kubernetes-helm.github.io/monocular
# 安装
helm install monocular/monocular -f custom-repos.yaml
# custom-repos.yaml 内容
cat custom-repos.yaml
api:
config:
repos:
- name: stable
url: https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts
source: https://github.com/kubernetes/charts/tree/master/stable
- name: incubator
url: https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts-incubator
source: https://github.com/kubernetes/charts/tree/master/incubator
- name: monocular
url: https://kubernetes-helm.github.io/monocular
source: https://github.com/kubernetes-helm/monocular/tree/master/charts
5)查看K8S中已安装的charts:
helm list
NAME REVISION UPDATED STATUS CHART NAMESPACE
amber-seal 1 Mon Jul 2 17:29:25 2018 DEPLOYED nginx-ingress-0.9.5 default
my-release 1 Mon Jul 2 15:19:44 2018 DEPLOYED spark-0.1.10 default
nonplussed-panther 1 Mon Jul 2 17:27:41 2018 FAILED nginx-ingress-0.9.5 default
turbulent-tuatara 1 Mon Jul 2 17:31:33 2018 DEPLOYED monocular-0.6.2 default
6)删除安装的charts:
# 删除:helm delete xxx
helm delete amber-seal
执行命令,加 –force强制卸载
helm reset 或
helm reset --force
参考地址:https://github.com/gjmzj/kubeasz/blob/master/docs/guide/helm.md
https://blog.csdn.net/wenwenxiong/article/details/79067054
https://blog.csdn.net/luanpeng825485697/article/details/80873236