Helm安装笔记

### 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

```


分享到:


相關文章: