如何使用同一 k8s 集群内的 kubectl exec 从另一个 pod 中的一个 pod 执行命令

Sam*_*eni 7 rbac kubernetes kubectl

我在一个集群中有两个 Pod。让我们称它们为 A 和 B。我已经在 pod A 中安装了 kubectl,并且我正在尝试使用 pod A 从 pod B 运行命令kubectl exec -it podB -- bash。我收到以下错误

Error from server (Forbidden): pods "B" is forbidden: User "system:serviceaccount:default:default" cannot create pods/exec in the namespace "default"

我创建了以下 Role 和 RoleBinding 来获取访问权限。角色yaml

kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: api-role
  namespace: default
  labels:
    app: tools-rbac
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
Run Code Online (Sandbox Code Playgroud)

角色绑定 yaml

kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: global-rolebinding
  namespace: default
  labels:
    app: tools-rbac
subjects:
- kind: Group
  name: system:serviceaccounts
  apiGroup: rbac.authorization.k8s.io
Run Code Online (Sandbox Code Playgroud)

任何帮助是极大的赞赏。谢谢

cod*_*ger 5

pods/exec除了pods您拥有的权限之外,您还需要授予对子资源的访问权限。也就是说,这是一件非常奇怪的事情,并且可能会非常努力地思考这是否是最好的解决方案。