无法将命名空间字段添加到 RoleBinding 中的 roleRef
Can't to add namespace field to roleRef in RoleBinding
我想在我的 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
我得到:
error: error validating "MyRoleBinding.yaml": error validating data:
ValidationError(RoleBinding.roleRef): unknown field "namespace" in
io.k8s.api.rbac.v1.RoleRef; if you choose to ignore these errors, turn
validation off with --validate=false
我运行宁在default
命名空间,是因为这个吗?
我试着 运行:
kubectl apply -f MyRoleBinding.yaml --namespace=kube-system
但我遇到了同样的错误。
我还尝试使用以下方法在 defaul
命名空间中添加现有角色:
roleRef:
kind: Role
name: read-pods
namespace: default
apiGroup: ""
我也遇到了同样的错误。
RoleRef 不支持命名空间子句,摘自 source code:
// 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"`
}
roleRef
字段不支持命名空间。您可以将 roleRef
与未命名空间的 ClusterRoles 一起使用,或者与始终必须与 RoleBinding 位于同一命名空间中的 Roles 一起使用。另见 reference.
我想在我的 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
我得到:
error: error validating "MyRoleBinding.yaml": error validating data: ValidationError(RoleBinding.roleRef): unknown field "namespace" in io.k8s.api.rbac.v1.RoleRef; if you choose to ignore these errors, turn validation off with --validate=false
我运行宁在default
命名空间,是因为这个吗?
我试着 运行:
kubectl apply -f MyRoleBinding.yaml --namespace=kube-system
但我遇到了同样的错误。
我还尝试使用以下方法在 defaul
命名空间中添加现有角色:
roleRef:
kind: Role
name: read-pods
namespace: default
apiGroup: ""
我也遇到了同样的错误。
RoleRef 不支持命名空间子句,摘自 source code:
// 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"`
}
roleRef
字段不支持命名空间。您可以将 roleRef
与未命名空间的 ClusterRoles 一起使用,或者与始终必须与 RoleBinding 位于同一命名空间中的 Roles 一起使用。另见 reference.