gpt4 book ai didi

kubernetes - ServiceAccount 无法在命名空间中列出资源 "pods",尽管它具有具有适当资源的角色

转载 作者:行者123 更新时间:2023-12-02 11:39:11 24 4
gpt4 key购买 nike

我的自定义命名空间中有以下定义:

apiVersion: v1
kind: ServiceAccount
metadata:
name: test-sa
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: test
rules:
- apiGroups: [""]
resources: ["pods", "pods/exec"]
verbs: ["get", "list", "delete", "patch", "create"]
- apiGroups: ["extensions", "apps"]
resources: ["deployments", "deployments/scale"]
verbs: ["get", "list", "delete", "patch", "create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: test
subjects:
- kind: User
name: test-sa
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: test
apiGroup: rbac.authorization.k8s.io

运行 describe role test
Name:         test
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"rbac.authorization.k8s.io/v1","kind":"Role","metadata":{"annotations":{},"name":"test","namespace":"test-namesapce...
PolicyRule:
Resources Non-Resource URLs Resource Names Verbs
--------- ----------------- -------------- -----
pods/exec [] [] [get list delete patch create]
pods [] [] [get list delete patch create]
deployments.apps/scale [] [] [get list delete patch create]
deployments.apps [] [] [get list delete patch create]
deployments.extensions/scale [] [] [get list delete patch create]
deployments.extensions [] [] [get list delete patch create]

当我尝试运行命令时 kubectl get pods在使用此服务帐户的 pod 中,我收到以下错误:

Error from server (Forbidden): pods is forbidden: User "system:serviceaccount:test-namespace:test-sa" cannot list resource "pods" in API group "" in the namespace "test-namespace"



哪里配置错了?

最佳答案

问题出在 subjectsRoleBinding .正确的定义是:

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: test
subjects:
- kind: ServiceAccount
name: test-sa
roleRef:
kind: Role
name: test
apiGroup: rbac.authorization.k8s.io

关于kubernetes - ServiceAccount 无法在命名空间中列出资源 "pods",尽管它具有具有适当资源的角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59375922/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com