### Helm官方文檔
https://helm.sh/docs/intro/quickstart/
```
https://github.com/helm/helm/releases/tag/v2.16.4
wget https://get.helm.sh/helm-v2.16.4-linux-amd64.tar.gz
```
### 安裝Helm客戶端
> [官網安裝文檔](https://v2.helm.sh/docs/using_helm/#installing-helm)
```
tar -zxvf helm-v2.16.4-linux-amd64.tar.gz
cp linux-amd64/helm /usr/local/bin/
```
helm version測試和打印信息,可以看到Helm Client的版本信息,Helm tiller的還是Error狀態。
```
Client: &version.Version{SemVer:"v2.16.4", GitCommit:"5e135cc465d4231d9bfe2c5a43fd2978ef527e83", GitTreeState:"clean"}
Error: could not find tiller
```
### 安裝Helm的Server端 Tiller
https://v2.helm.sh/docs/using_helm/#installing-helm
> Check the [Kubernetes Distribution Guide](https://v2.helm.sh/docs/using_helm/##kubernetes-distribution-guide) to see if there’s any further points of interest on using Helm with your cloud provider. Also check out the guide on [Tiller and Role-Based Access Control](https://v2.helm.sh/docs/using_helm/#role-based-access-control) for more information on how to run Tiller in an RBAC-enabled Kubernetes cluster.
#### service account with cluster-admin role
```
# vim rbac-config.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: tiller
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: tiller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: tiller
namespace: kube-system
```
```console
kubectl create -f rbac-config.yaml
serviceaccount "tiller" created
clusterrolebinding "tiller" created
```
#### Tiller 安裝
```
helm init --service-account tiller --history-max 200
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.
To prevent this, run `helm init` with the --tiller-tls-verify flag.
For more information on securing your installation see: https://v2.helm.sh/docs/securing_installation/
```
kubectl get pod -n kube-system -o wide
查看pod是否是running狀態,如果報鏡像錯誤,可以從阿里雲pull
```
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.16.4
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.16.4 gcr.io/kubernetes-helm/tiller:v2.16.4
```
helm version現在可以看到Client和Server正常顯示
```
Client: &version.Version{SemVer:"v2.16.4", GitCommit:"5e135cc465d4231d9bfe2c5a43fd2978ef527e83", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.16.4", GitCommit:"5e135cc465d4231d9bfe2c5a43fd2978ef527e83", GitTreeState:"clean"}
```
helm 有很多子命令和參數,為了提高使用命令行的效率,
通常建議安裝 helm 的 bash 命令補全腳本,方法如下:
```
# source
# echo "source > ~/.bashrc
```
helm init --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.16.4 --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
#### 更換倉庫
> 默認的charts倉庫在googleapi網站上,速度比較慢,這裡我們更換為阿里雲的charts倉庫
>
> 手動更換stable 存儲庫為阿里雲的存儲庫
```
# 先移除原先的倉庫
helm repo remove stable
# 添加新的倉庫地址
helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
# 更新倉庫
helm repo update
```
### Helm卸載
```
# helm reset
```
### 遇到的問題
1. helm版本,v2和v3的區別
2. helm v2.16.4運行時報錯,降級到v2.16.1運行正常
> k8s集群版本: v1.17.3
> helm版本:v2.16.4 (latest)
錯誤信息如下:
```
# helm install --name test001 -f values.yaml .
Error: validation failed: [serviceaccounts "test001-mychart" not found, services "test001-mychart" not found, deployments.apps "test001-mychart" not found]
[storage] 2020/03/25 16:53:08 getting release history for "els6"
[tiller] 2020/03/25 16:53:08 rendering elasticsearch chart using values
2020/03/25 16:53:08 info: manifest "elasticsearch/templates/master-pdb.yaml" is empty. Skipping.
2020/03/25 16:53:08 info: manifest "elasticsearch/templates/client-pdb.yaml" is empty. Skipping.
2020/03/25 16:53:08 info: manifest "elasticsearch/templates/data-pdb.yaml" is empty. Skipping.
[tiller] 2020/03/25 17:20:29 performing install for test001
[tiller] 2020/03/25 17:20:29 executing 1 crd-install hooks for test001
[tiller] 2020/03/25 17:20:29 hooks complete for crd-install test001
[tiller] 2020/03/25 17:20:29 failed install perform step: validation failed: [serviceaccounts "test001-mychart" not found, services "test001-mychart" not found, deployments.apps "test001-mychart" not found
```
閱讀更多 用戶53036930380 的文章