我想做一个非常简单的例子来学习如何在 Kubernetes 中使用 RBAC 授权。因此我使用文档中的示例:
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: dev
name: dev-readpods-role
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "watch", "list"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: dev-tester-rolebinding
namespace: dev
subjects:
- kind: User
name: Tester
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: dev-readpods-role
apiGroup: rbac.authorization.k8s.io
创建角色和角色绑定。
当我使用 Tester 登录并尝试
kubectl get pods -n dev
我明白了
Error from server (Forbidden): pods is forbidden: User "<url>:<port>/oidc/endpoint/OP#Tester" cannot list pods in the namespace "dev"
我在这里读到(Kubernetes 中的 RBAC 错误),api-server 必须以 --authorization-mode=...,RBAC 启动。我怎样才能检查这个?我在别的地方读到,如果我跑
kubectl api-versions | findstr rbac
并找到条目 RBAC 应该被激活。真的吗?
我究竟做错了什么?有什么好办法解决问题吗?
谢谢!
PS 我在 IBM Cloud Private 中运行 kubernetes。