kubenetes1.16.0 安装helm报错与解决办法

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"

执行如下命令:

kubectl create serviceaccount --namespace kube-system tiller
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'      
helm init --service-account tiller --upgrade
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 -

你可能感兴趣的:(k8s)