首页 > 解决方案 > 服务被禁止:用户 \"system:anonymous\" 无法列出命名空间 \"kube-system\ 中的服务

问题描述

我在 VirtualBox 上创建了一个新的 kubernetes 集群。我有一个主节点和两个工作节点。我想使用仪表板,但出现错误。当我运行kubectl proxymaster 开始监听端口 8001 时:

Starting to serve on 127.0.0.1:8001

然后我在我的主机上创建一个 SSH 隧道:

ssh user@10.10.10.50 -N -L 8001:127.0.0.1:8001

但是当我localhost:8001/ui在浏览器上输入时,我得到了这个:

{
  "paths": [
    "/apis",
    "/apis/",
    "/apis/apiextensions.k8s.io",
    "/apis/apiextensions.k8s.io/v1beta1",
    "/healthz",
    "/healthz/etcd",
    "/healthz/ping",
    "/healthz/poststarthook/generic-apiserver-start-informers",
    "/healthz/poststarthook/start-apiextensions-controllers",
    "/healthz/poststarthook/start-apiextensions-informers",
    "/metrics",
    "/openapi/v2",
    "/swagger-2.0.0.json",
    "/swagger-2.0.0.pb-v1",
    "/swagger-2.0.0.pb-v1.gz",
    "/swagger.json",
    "/swaggerapi",
    "/version"
  ]
}

如果我想直接通过 api 进入仪表板:

https://10.10.10.50:6443/api/v1/namespaces/kube-system/services

我收到此错误:

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {

  },
  "status": "Failure",
  "message": "services is forbidden: User \"system:anonymous\" cannot list services in the namespace \"kube-system\"",
  "reason": "Forbidden",
  "details": {
    "kind": "services"
  },
  "code": 403
}

我知道这与身份验证有关,但我不知道应该如何在集群上定义用户名/密码或在主节点和主机之间共享密钥。或者我应该如何使用 .kube/config 文件中的密钥。

标签: linuxkubernetesubuntu-16.04kubernetes-dashboard

解决方案


我想使用仪表板,但出现错误。

根据仪表板文档的摘录,成功默认安装仪表板后(默认仪表板部署包含运行所需的最小 RBAC 权限集):

  • 要从本地工作站访问 Dashboard,您必须为 Kubernetes 集群创建一个安全通道。运行以下命令:

    kubectl proxy
    
  • 现在访问仪表板:

    http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
    

无需进行隧道或任何其他更改。到目前为止,仪表板的默认安装总是像一个魅力,如果你有任何单独配置,那么可能会有一些问题......


推荐阅读