首页 > 解决方案 > 如何配置卷(第二部分)?

问题描述

我正在尝试配置 RBAC,以便我可以配置卷。这是此(如何正确地为 argo 提供卷?)线程的后续。添加角色将错误从“无法获取资源”更改为“无法创建资源”。

我现在认为这是一个 Kubernetes 问题,但仍然不明白如何解决它。

错误:

Error from server (Forbidden): error when creating "/tmp/manifest.yaml": persistentvolumeclaims is forbidden: User "system:serviceaccount:argo:argo" cannot create resource "persistentvolumeclaims" in API group "" in the namespace "argo" 

角色.yaml

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: workflow
  namespace: argo
rules:
- apiGroups:
  - ""
  resources:
  - pods
  verbs:
  - get
  - list
  - watch
  - create
  - update
  - patch
  - delete
- apiGroups:
  - ""
  resources:
  - pods/log
  verbs:
  - get
  - list
  - watch
  - create
  - update
  - patch
  - delete
- apiGroups:
  - ""
  resources:
   - persistentvolumeclaims
  verbs:
  - get
  - list
  - watch
  - create
  - update
  - patch
  - delete

标签: kubernetesvolumepersistent-volume-claims

解决方案


RBAC 身份验证规则配置有 K8s 资源,可分为两组:

  • Roles其中ClusterRole指定可以对哪些资源执行哪些动词/动作。
  • RoleBindings并将ClusterRoleBindings上述角色绑定到特定的用户、组或 ServiceAccounts。

在您的情况下,您已成功创建,但简而言之,Roles您缺少的是可以执行您已经指定的操作的人。RoleBindings

可以使用 yaml 文件创建角色绑定:

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: workflow-argo
  namespace: argo
subjects:
# You can specify more than one "subject"
- kind: User
  name: jane # "name" is case sensitive
  apiGroup: rbac.authorization.k8s.io
roleRef:
  # with "roleRef" you specify the binding to a Role / ClusterRole
  kind: Role 
  name: workflow # here you have to reference the name of your Role
  apiGroup: rbac.authorization.k8s.io

或使用命令:

kubectl create rolebinding workflow-argo --clusterrole=workflow --user=jane --namespace=argo

有关更多信息,请查看 K8s 部分:使用 RBAC 授权


推荐阅读