无法将命名空间字段添加到角色绑定中的角色引用



我想在我的MyRoleBinding.yaml文件中添加来自命名空间kube-system的角色,如下所示:

kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata: 
name: myrolebinding
namespace: default
subjects: 
- kind: ServiceAccount 
name: myservice
namespace: default
apiGroup: ""
roleRef: 
kind: Role
name: system:controller:token-cleaner
namespace: kube-system
apiGroup: "" 

但是当我跑kubectl apply -f MyRoleBinding.yaml时,我得到:

错误:验证"MyRoleBinding.yaml"时出错:验证数据时出错: ValidationError(RoleBinding.roleRef(:未知字段"namespace" in io.k8s.api.rbac.v1.RoleRef;如果您选择忽略这些错误,请转到 验证关闭 --验证=假

我在default命名空间中运行,是因为这个吗?
我试图运行:
kubectl apply -f MyRoleBinding.yaml --namespace=kube-system但我遇到了同样的错误。

我还尝试使用以下方法在defaul命名空间中添加现有角色:

roleRef: 
kind: Role
name: read-pods
namespace: default
apiGroup: "" 

我得到了同样的错误。

roleRef字段不支持命名空间。您可以将roleRef与未命名的群集角色一起使用,也可以与必须始终与角色绑定位于同一命名空间中的角色一起使用。另请参阅参考资料。

RoleRef 不支持命名空间子句,摘自源代码:

// RoleRef contains information that points to the role being used
type RoleRef struct {
// APIGroup is the group for the resource being referenced
APIGroup string `json:"apiGroup" protobuf:"bytes,1,opt,name=apiGroup"`
// Kind is the type of resource being referenced
Kind string `json:"kind" protobuf:"bytes,2,opt,name=kind"`
// Name is the name of resource being referenced
Name string `json:"name" protobuf:"bytes,3,opt,name=name"`
}

最新更新