【问题标题】:What role permissions are required to support “rollout undo”?支持“推出撤消”需要哪些角色权限?
【发布时间】:2021-01-24 19:05:03
【问题描述】:

我正在尝试为我们的 CI/CD 服务器设置一个角色,该角色可以支持回滚失败的部署。当前权限用于更新部署和相关资源并监视其状态,但是当我尝试以 CI 用户身份运行例如“kubectl rollout undo deployment/admin”时,我收到错误:

错误:无法从部署管理员检索副本集:replisets.apps 被禁止:用户“ci-admin”无法在命名空间“acceptance”中的 API 组“apps”中列出资源“replicasets”

这是最初的角色配置:

# Server role that allows CI to push application deployments to Kubernetes
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: deployment-role
  namespace: acceptance
rules:
  - apiGroups: ["*"]
    resources: ["deployments"]
    resourceNames: ["admin", "backend", "web"]
    verbs: ["patch", "update", "watch"]
  - apiGroups: ["*"]
    resources: ["deployments"]
    verbs: ["get", "list"]
  - apiGroups: ["*"]
    resources: ["configmaps"]
    resourceNames: ["admin-fluent-bit-config", "backend-fluent-bit-config", "web-fluent-bit-config"]
    verbs: ["patch", "update", "watch"]
  - apiGroups: ["*"]
    resources: ["configmaps"]
    verbs: ["get", "list"]
  - apiGroups: ["*"]
    resources: ["horizontalpodautoscalers"]
    resourceNames: ["backend"]
    verbs: ["delete", "patch", "update"]
  - apiGroups: ["*"]
    resources: ["horizontalpodautoscalers"]
    verbs: ["create", "get", "list"]
  - apiGroups: ["*"]
    resources: ["events", "pods", "pods/log"]
    verbs: ["get", "list"]

我尝试添加权限以获取和列出副本集以解决错误:

  - apiGroups: ["*"]
    resources: ["deployments", "replicasets"]
    verbs: ["get", "list"]

但我仍然遇到与以前相同的错误。

Kubernetes 文档根本没有帮助,因为似乎没有任何给定命令所需权限的完整列表。只有少数几个例子。

谁能告诉回滚需要什么权限?

【问题讨论】:

  • 也许尝试使用“extensions”、“apps” apiGroups 而不是“*”?

标签: kubernetes kubernetes-rbac


【解决方案1】:

正如@ForgetfulFellow 所说,您必须在apiGroups 中添加extensionsapps

此外,您必须在resources 字段中添加replicasets,因为没有它您将收到以下错误:

error: failed to retrieve replica sets from deployment sample-deploy: replicasets.apps is forbidden: User "user" cannot list resource "replicasets" in API group "apps" in the namespace "acceptance"

【讨论】:

    【解决方案2】:

    我今天早上又试了一次,它就像最初写的那样奏效了。

    我对发生的事情的最佳猜测是 CI 当时实际上在不同的集群上运行。我们的客户在 9 月将验收环境转移到了一个新的 AWS 账户,但直到 10 月中旬,旧环境才完全清理干净。当我从我的开发盒中对新集群中的角色进行更改时,CI 服务器肯定仍在使用旧集群的上下文,我没有注意到它,因为它们都具有相同的名称。 :/

    抱歉误报。

    【讨论】:

      猜你喜欢
      • 2013-01-18
      • 2022-01-27
      • 2020-04-06
      • 2014-08-28
      • 1970-01-01
      • 2015-12-28
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      相关资源
      最近更新 更多