我正在尝试从另一个容器访问所有名称空间和容器。因此,我创建了clusterrole,clusterrolebinding和服务帐户。我能够访问唯一的客户名称空间资源。但是我需要访问所有名称空间资源。有可能吗?
apiVersion: v1
kind: ServiceAccount
metadata:
name: spinupcontainers
namespace: customer
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: spinupcontainers
namespace: customer
rules:
- apiGroups: [""]
resources: ["pods", "pods/exec"]
verbs: ["get", "list", "delete", "patch", "create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: spinupcontainers
namespace: customer
subjects:
- kind: ServiceAccount
name: spinupcontainers
roleRef:
kind: ClusterRole
name: spinupcontainers
apiGroup: rbac.authorization.k8s.io
有人可以帮助解决此问题吗?
预先感谢
答案 0 :(得分:6)
在您的YAML示例中,您似乎使用的是RoleBinding
而不是ClusterRoleBinding
。 RoleBinding
仅在名称空间内授予这些权限。另请参见Kubernetes Documentation on this topic:
RoleBinding授予特定命名空间中的权限,而 ClusterRoleBinding授予访问整个群集的权限。
答案 1 :(得分:0)
首先,您应该为部署创建服务,例如,如果该服务的名称为test-service且它在测试名称空间中运行,则应与该服务进行通信,例如test-service.test。在kubedns中,test-service.test将解析为ip,您可以与其他命名空间中的服务进行通信