Kubernetes:来自服务器的错误(禁止):用户&系统:匿名&即使在授予权限后也无法列出群集作用域中的节点 [英] kubernetes: Error from server (Forbidden): User "system:anonymous" cannot list nodes at the cluster scope even after granting permission

查看:18
本文介绍了Kubernetes:来自服务器的错误(禁止):用户&系统:匿名&即使在授予权限后也无法列出群集作用域中的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使在向用户授予集群角色后,我也会收到Error from server (Forbidden): User "system:anonymous" cannot list nodes at the cluster scope. (get nodes)

我为用户设置了以下内容:

- context:
    cluster: kubernetes
    user: user@gmail.com
  name: user@kubernetes`  set in the ~/.kube/config file

和以下代码添加到admin.yaml以创建集群角色和集群角色绑定:

kind: CluserRouster: kubernetes    user: nsp@gmail.com  name: nsp@kubernetese
apiVersion: rbac.authorization.k8s.io/v1alpha1
metadata:
  name: admin-role
rules:
  - apiGroups: ["*"]
    resources: ["*"]
    verbs: ["*"]
---
oidckind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1alpha1
metadata:
  name: admin-binding
subjects:
  - kind: User
    name: nsp@gmail.com
roleRef:
  kind: ClusterRole
  name: admin-role

当我尝试该命令时,仍收到错误。

kubectl --username=user@gmail.com get nodes
Error from server (Forbidden): User "system:anonymous" cannot list nodes at the cluster scope. (get nodes)

请建议如何继续。

推荐答案

您的问题不在于您的集群角色绑定,而在于用户身份验证。Kubernetes告诉您,它将您标识为system:anonymous(类似于*Nix的无名氏),而不是nsp@example.com(您对其应用了绑定)。

在您的特定情况下,原因是username标志使用HTTP基本身份验证,并且需要password标志才能实际执行任何操作。但是,即使您提供了密码,您仍然需要实际告诉API服务器接受该特定用户。

查看Kubernetes文档中涉及不同身份验证方法的this部分。要使usernamepassword身份验证起作用,您需要查看静态密码文件部分,但实际上我建议您使用X509客户端证书,因为它们更安全,操作也更简单(服务器上没有秘密,API服务器之间没有状态可供复制)。

这篇关于Kubernetes:来自服务器的错误(禁止):用户&系统:匿名&即使在授予权限后也无法列出群集作用域中的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆