官方部署文档:https://github.com/helm/helm/blob/master/docs/rbac.md
需要提前配置kubectl可以连接到集群
1、下载软件包
wget https://storage.googleapis.com/kubernetes-helm/helm-v2.16.8-linux-amd64.tar.gz
2、解压helm
tar -zxvf helm-v2.12.0-linux-amd64.tar.gz
3、复制客户端执行文件到 bin 目录下
cp linux-amd64/helm /usr/local/bin/
4、安装 Helm 服务器端 Tiller
helm init --upgrade --tiller-image registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.16.8 --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
5、创建 Kubernetes 的服务帐号和绑定角色
kubectl create serviceaccount --namespace kube-system tiller
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
6、为 Tiller 设置帐号, 使用 kubectl patch 更新 API 对象
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
7、查看是否授权成功
kubectl get deploy --namespace kube-system tiller-deploy --output yaml|grep serviceAccount
kubectl get sa -n kube-system|grep tiller
8、验证 Tiller 是否安装成功
kubectl -n kube-system get pods|grep tiller
helm version
如果提示portforward.go:400] an error occurred forwarding的报错需要安装socat这个包
yum -y install socat
9、卸载 Helm 服务器端 Tiller
helm reset
10、设置helm自动补全
echo ". /etc/bash_completion" >> ~/.bashrc && source ~/.bashrc
echo "source <(helm completion bash)" >> ~/.bashrc && source ~/.bashrc
11、helm安装在指定namespace,在集群外部虚拟机部署服务
集群内部署helm在deploy这个namespace
kubectl create deploy
helm init --upgrade --tiller-namespace deploy --tiller-image registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.16.8 --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
kubectl create serviceaccount --namespace deploy tiller
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=deploy:tiller
kubectl patch deploy --namespace deploy tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
把集群凭证放到集群外部节点、并配置kubectl和集群同版本helm,执行以下命令验证和部署服务
helm version --tiller-namespace deploy
helm --tiller-namespace deploy install ./
12、k8s1.16版本以上部署helm注意事项
报错信息如下:
root@ops-duanshuaixing:~# helm init --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.12.2 --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
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.
Error: error installing: the server could not find the requested resource****
解决办法:
对于 Kubernetes v1.16.0 以上的版本,有可能会碰到 Error: error installing: the server could not find the requested resource 的错误。这是由于 extensions/v1beta1 已经被 apps/v1 替代。
helm init -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.11.0 --stable-repo-url http://mirror.azure.cn/kubernetes/charts/ --service-account tiller --override spec.selector.matchLabels.'name'='tiller',spec.selector.matchLabels.'app'='helm' --output yaml | sed 's@apiVersion: extensions/v1beta1@apiVersion: apps/v1@' | kubectl apply -f -