即使创建角色绑定后,Kubernetes 也无法在集群范围内的 API 组“”中创建资源“命名空间”

iaq*_*obe 5 gitlab-ci kubernetes

我正在运行一个创建 kubernetes 命名空间的管道,但是当我运行它时,我得到:

Error from server (Forbidden): namespaces is forbidden: User "system:serviceaccount:gitlab-runner:default" cannot create resource "namespaces" in API group "" at the cluster scope
Run Code Online (Sandbox Code Playgroud)

我创建了 aClusterRole和 a来允许命名空间中的ClusterRoleBinding服务用户使用以下命令创建命名空间:defaultgitlab-runner

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: modify-namespace
rules:
  - apiGroups: [""]
    resources:
      - namespace
    verbs:
      - create
Run Code Online (Sandbox Code Playgroud)

和:

ind: ClusterRoleBinding
metadata:
  name: modify-namespace-binding
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: modify-namespace
subjects:
- kind: ServiceAccount
  name: default
  namespace: gitlab-runner
Run Code Online (Sandbox Code Playgroud)

但这给了我同样的错误。我究竟做错了什么?

Sai*_*nti 6

  • [""] 在 clusterrole 清单中它应该只是"". 因为 [""] 将是 apiGroups 需要字符串的数组。
  • 根据resourcesnamespaces不应该是namespace因为:
kubectl api-resources | grep 'namespace\|NAME'
NAME                              SHORTNAMES   APIVERSION                             NAMESPACED   KIND
namespaces                        ns           v1                                     false        Namespace
Run Code Online (Sandbox Code Playgroud)
  • 因此 clusterrole 清单应如下所示:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: modify-namespace
rules:
  - apiGroups: ""
    resources:
      - namespaces
    verbs:
      - create
Run Code Online (Sandbox Code Playgroud)

  • 我有同样的错误,但这个解决方案对我不起作用。 (3认同)