【发布时间】:2020-04-10 13:31:00
【问题描述】:
我在 k8s 集群中创建了以下对象。
- 命名空间(testpsp)
- 自定义 ServiceAccount (testuser)
- 角色和角色绑定通过。清单文件
请参阅下面的 yaml 文件以获取 Role 和 RoleBinding 资源。
$ cat developer.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: developer
namespace: testpsp
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- create
- apiGroups:
- extensions
- apps
resources:
- deployments
- replicasets
verbs:
- '*'
$ cat developer-binding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: developer-binding
namespace: testpsp
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: developer
subjects:
- kind: ServiceAccount
name: testuser
正如您在上述角色清单文件中看到的,我已将Pod 资源的CREATE 权限 授予testuser 服务帐户。但我仍然收到错误消息。
错误
来自服务器的错误(禁止):创建“hello-pod.yaml”时出错:pods 被禁止:用户“testuser”无法在命名空间“testpsp”中的 API 组“”中创建资源“pods”
这是 Pod yaml 文件。我在这里错过了什么吗?
$ cat hello-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: hello-pod
namespace: testpsp
spec:
serviceAccountName: testuser
containers:
- name: hello-kubernetes
image: paulbouwer/hello-kubernetes:1.5
ports:
- containerPort: 8080
这是我正在运行以创建 Pod 的命令。
$ kubectl --as=testuser -n testpsp create -f hello-pod.yaml
【问题讨论】:
标签: kubernetes google-kubernetes-engine