我是k8s的新手。
我在k8test
(自定义)名称空间中有一个单独的pod的部署。 出于学习目的 ,我想授予该pod管理员访问权限。
我无法通过创建命名空间角色来实现这一目标:
kind: 'Role',
apiVersion: 'rbac.authorization.k8s.io/v1',
metadata: {
name: 'super-duper-admin',
namespace: 'k8test',
},
rules: [
{
apiGroups: [''],
resources: ['ResourceAll'],
verbs: ['VerbAll'],
},
],
从广告连播的日志中:
服务被禁止:用户“ system:serviceaccount:k8test:default”无法在名称空间“ k8test”的API组“”中列出资源“ services”
apiGroups
的简单说明。是什么?答案 0 :(得分:2)
您可以找到所有api组here。
根据here
API组使扩展Kubernetes API更容易。 API组 是在REST路径和apiVersion字段中指定的 序列化的对象
Pod位于core
API组和版本v1
下。
在您的RBAC中,''
表示core
API组。
创建以下角色,该角色将授予所有apigroups
,所有resources
和所有verbs
权限。
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: k8test
name: super-duper-admin
rules:
- apiGroups:
- '*'
resources:
- '*'
verbs:
- '*'
按如下所示将角色绑定到服务帐户
apiVersion: rbac.authorization.k8s.io/v1
# This role binding allows "jane" to read pods in the "default" namespace.
# You need to already have a Role named "pod-reader" in that namespace.
kind: RoleBinding
metadata:
name: admin-rolebinding
namespace: k8test
subjects:
# You can specify more than one "subject"
- kind: ServiceAccount
name: default # "name" is case sensitive
namespace: k8test
roleRef:
# "roleRef" specifies the binding to a Role / ClusterRole
kind: Role #this must be Role or ClusterRole
name: super-duper-admin # this must match the name of the Role or ClusterRole you wish to bind to
apiGroup: rbac.authorization.k8s.io
执行以下命令以验证RABC是否正确应用
kubectl auth can-i list services --as=system:serviceaccount:k8test:default -n k8test
有关RBAC here的更多信息和示例