Can I connect one service account to multiple namespaces in Kubernetes? Can I connect one service account to multiple namespaces in Kubernetes? kubernetes kubernetes

Can I connect one service account to multiple namespaces in Kubernetes?


You can simply reference a ServiceAccount from another namespace in the RoleBinding:

apiVersion: rbac.authorization.k8s.io/v1beta1kind: Rolemetadata:  name: pod-reader  namespace: ns2rules:- apiGroups: [""]  resources: ["pods"]  verbs: ["get", "list", "watch"]---apiVersion: rbac.authorization.k8s.io/v1kind: RoleBindingmetadata:  name: pod-reader-from-ns1  namespace: ns2roleRef:  apiGroup: rbac.authorization.k8s.io  kind: Role  name: pod-readersubjects:- kind: ServiceAccount  name: ns1-service-account  namespace: ns1