helm:Error: could not find tiller

報錯信息如下:
root@8:~# helm version
Client: &version.Version{SemVer:"v2.14.1", GitCommit:"5270352a09c7e8b6e8c9593002a73535276507c0", GitTreeState:"clean"}
Error: could not find tiller
root@8:~# ./get_helm.sh --version v2.14.1
Downloading https://get.helm.sh/helm-v2.14.1-linux-amd64.tar.gz
Preparing to install helm and tiller into /usr/local/bin
helm installed into /usr/local/bin/helm
tiller installed into /usr/local/bin/tiller
Run 'helm init' to configure helm.
root@8:~# helm init
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.
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 替代。相信在2.15 或者 3 版本發佈之後, 應該就不會遇到這個問題了。還是生態比較慢的原因。

解決方法是使用如下語句安裝
helm init -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.14.3 --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 -

設置 --tiller-image --service-account 參數 安裝helm

檢查一下是不是安裝成功了
kubectl get pods -n kube-system | grep tiller

root@rancherk8sm1:~# helm version
Client: &version.Version{SemVer:"v2.12.1", GitCommit:"02a47c7249b1fc6d8fd3b94e6b4babf9d818144e", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.12.1", GitCommit:"02a47c7249b1fc6d8fd3b94e6b4babf9d818144e", GitTreeState:"clean"}

替換 repo 爲阿里鏡像,注意上面的命令已經做了這一步,所以不用做了。這裏是對尚未替換repo的情況下,如何替換repo的介紹。

root@rancherk8sm1:~# helm repo list
NAME    URL
stable  https://kubernetes-charts.storage.googleapis.com
local   http://127.0.0.1:8879/charts

root@rancherk8sm1:~# helm repo remove stable
"stable" has been removed from your repositories

root@rancherk8sm1:~# helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
"stable" has been added to your repositories
root@rancherk8sm1:~# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Skip local chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈

root@rancherk8sm1:~# helm repo list
NAME    URL
local   http://127.0.0.1:8879/charts
stable  https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
root@rancherk8sm1:~#

###########################################################
###########################################################

1. 安裝Helm客戶端

方式一:
公有云環境可以使用官方安裝腳本一鍵安裝,只需要執行如下一條命令:

curl https://raw.githubusercontent.com/helm/helm/master/scripts/get |bash

方式二:
內網環境可以手動下載安裝,下載地址:https://github.com/kubernetes/helm/releases

tar -zxvf helm-2.14.1.tar.gz
mv helm-2.14.1/helm /usr/local/bin/helm

執行helm version命令驗證:
目前只能查看到客戶端的版本,服務器還沒有安裝

[root@master1 helm]# helm version
Client: &version.Version{SemVer:"v2.14.1", GitCommit:"5270352a09c7e8b6e8c9593002a73535276507c0", GitTreeState:"clean"}
Error: could not find a ready tiller pod

安裝helm的bash命令補全腳本:

helm completion bash > .hermrc ;echo "source .helmrc" >> .bashrc
2.安裝Tiller服務器

正常情況下執行 helm init 即可,
但是在kubernetes 1.16.0及之後的版本上執行卻報如下錯誤:

helm init
$HELM_HOME has been configured at /root/.helm.
Error: error installing: the server could not find the requested resource

原因是因爲1.16.0之後的deployment 的apiversion的endpoint發生了變化需要做如下處理:

輸出tiller的定義文件

> helm init --output yaml > tiller.yaml
#修改定義文件 apiVersion改爲apps/v1,並新增selector信息 如下:
> vim tiller.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: helm
    name: tiller
  name: tiller-deploy
  namespace: kube-system
spec:
  replicas: 1
  strategy: {}
  selector:
    matchLabels:
      app: helm
      name: tiller
...
#修改後執行定義文件
> kubectl apply -f tiller.yaml

執行後使用helm version查看,發現server已經安裝成功:

>  helm version
Client: &version.Version{SemVer:"v2.14.1", GitCommit:"5270352a09c7e8b6e8c9593002a73535276507c0", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.14.1", GitCommit:"5270352a09c7e8b6e8c9593002a73535276507c0", GitTreeState:"clean"}

執行helm list發現仍有報錯如下:

> helm list   
Error: configmaps is forbidden: User "system:serviceaccount:kube-system:default" cannot list resource "configmaps" in API group "" in the namespace "kube-system"

執行如下命令:

# 在kube-system命名空間中創建tiller賬戶
kubectl create serviceaccount --namespace kube-system tiller
# 創建角色並授予cluster-admin權限
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
#使用 kubectl patch 更新 API 對象
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'      
helm init --service-account tiller --upgrade
# 指定賬戶進行初始化,別忘了還要指定tiller鏡像哦
helm init --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 -

執行後tiller安裝成功。

注:關於這個報錯Error: error installing: the server could not find the requested resource
可以直接使用以下命令解決,就不會再報rbacx相關的錯誤了。

helm init --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 -
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章