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 -
发布了33 篇原创文章 · 获赞 0 · 访问量 3915

猜你喜欢

转载自blog.csdn.net/erhaiou2008/article/details/104014183