【问题标题】:Kubernetes dashboard error using service account token使用服务帐户令牌的 Kubernetes 仪表板错误
【发布时间】:2020-03-02 06:42:18
【问题描述】:

我有一个运行良好的各种资源的 Kubernetes 集群。我正在尝试使仪表板正常工作,但在启动仪表板并输入服务帐户令牌时出现以下错误。

persistentvolumeclaims 被禁止:用户 “system:serviceaccount:kube-system:kubernetes-dashboard”无法列出 命名空间中 API 组“”中的资源“persistentvolumeclaims” “默认”

它不允许列出我的集群中的任何资源(持久卷、Pod、入口等)。我的集群有多个命名空间。

这是我的服务帐户 yaml 文件:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: k8s-test # replace with your preferred username
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: dashboard-admin # replace with your preferred username
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: dashboard-admin # replace with your preferred username
  namespace: kube-system

感谢任何帮助。

【问题讨论】:

    标签: kubernetes kubernetes-dashboard


    【解决方案1】:

    修复:为集群角色创建角色绑定。

    这应该可以解决问题:

    kubectl delete clusterrole cluster-admin
    kubectl delete clusterrolebinding kubernetes-dashboard 
    kubectl create clusterrolebinding kubernetes-dashboard --clusterrole=cluster-admin --serviceaccount=kube-system:kubernetes-dashboard
    

    上述命令将创建一个角色绑定,赋予所有资源的所有权限。


    运行代理:

    kubectl proxy
    

    检查仪表板:请检查 kubectl 提供的 URL 和端口

    http://127.0.0.1:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/persistentvolume?namespace=default
    

    更多信息:集群角色:

    • 您可以通过以下方式查看“集群管理员”角色:

      kubectl edit clusterrole cluster-admin
      

    这里的问题是服务帐户“kubernetes-dashboard”没有资源“persistentVolumeClaims”的“列表”权限。

    【讨论】:

      【解决方案2】:

      我建议使用来自 Kubernetes 的 Web UI (Dashboard) 文档。

      部署仪表板 UI

      默认情况下不部署仪表板 UI。要部署它,请运行以下命令:

      kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta4/aio/deploy/recommended.yaml
      

      从您的 yaml 我可以看到您为命名空间 kube-system 指定了它们,但仪表板正在尝试列出命名空间 default 中的资源,至少您的错误消息中是这么说的。

      此外,您的yaml 似乎也与ServiceAccount name 不正确,因为在您拥有k8s-test 的文件中,错误消息显示它正在使用kubernetes-dashboard

      【讨论】:

        猜你喜欢
        • 2018-11-06
        • 1970-01-01
        • 2019-11-26
        • 2019-09-01
        • 2018-04-02
        • 2022-07-20
        • 2018-11-21
        • 2018-05-26
        • 2019-07-02
        相关资源
        最近更新 更多