如何授予所有 Kubernetes 服务帐户访问特定命名空间的权限?

ntv*_*t18 2 rbac kubernetes kubernetes-helm

我在 GCP 中有一个启用了 RBAC 的 Kubernetes 集群

一个命名空间的分蘖倍数服务

现在,我可以为特定服务帐户分配读者角色,因为它的全名

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  annotations:
    rbac.authorization.kubernetes.io/autoupdate: "true"
  name: tiller-reader
  namespace: tiller
rules:
  - apiGroups: [""]
    resources: ["pods"]
    verbs:
    - "get"
    - "watch"
    - "list"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: tiller-reader-role-binding
  namespace: tiller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: tiller-reader
subjects:
  - apiGroup: rbac.authorization.k8s.io
    kind: User
    name: system:serviceaccount:my-namespace-1:my-namespace-1-service-account
Run Code Online (Sandbox Code Playgroud)

服务的命名空间和帐户动态创建。如何自动授予所有服务帐户访问Tiller 命名空间的权限,例如:获取 Pod?

ili*_*efa 5

要向所有服务帐户授予角色,您必须使用组系统:serviceaccounts。

您可以尝试以下配置:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  annotations:
    rbac.authorization.kubernetes.io/autoupdate: "true"
  name: tiller-reader
  namespace: tiller
rules:
  - apiGroups: [""]
    resources: ["pods"]
    verbs:
    - "get"
    - "watch"
    - "list"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: tiller-reader-role-binding
  namespace: tiller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: tiller-reader
subjects:
  - apiGroup: rbac.authorization.k8s.io
    kind: Group
    name: system:serviceaccounts
Run Code Online (Sandbox Code Playgroud)