【问题标题】:How to add a new ClusterRoleBinding with Kustomize in k8s without removing existing bindings?如何在 k8s 中使用 Kustomize 添加新的 ClusterRoleBinding 而不删除现有绑定?
【发布时间】:2020-03-13 01:01:30
【问题描述】:

当我输入kubectl edit clusterrolebinding foo-role 时,我可以看到类似:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: foo-role
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: edit
subjects:
- kind: ServiceAccount
  name: foo-user
  namespace: ns1
- kind: ServiceAccount
  name: foo-user
  namespace: ns2

我可以通过将以下配置附加到上述文件来为命名空间ns3 添加一个新的ClusterRoleBinding:

- kind: ServiceAccount
  name: foo-user
  namespace: ns3

但是,我想使用 Kustomize 添加新的绑定,而不是手动修改上述文件。

我尝试在下面应用 .yaml 文件:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: foo-role
  selfLink: /apis/rbac.authorization.k8s.io/v1/clusterrolebindings/foo-role
  uid: 64a4a787-d5ab-4c83-be2b-476c1bcb6c96
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: edit
subjects:
- kind: ServiceAccount
  name: foo-user
  namespace: ns3

它确实在命名空间ns3 中添加了一个新的ClusterRoleBinding,但它会删除ns1 和ns2 的现有ClusterRoleBindings。

有没有办法使用 Kustomize 添加新的ClusterRoleBinding 而无需删除现有的?

【问题讨论】:

  • 以下 coderanger 的回答是否解决了您的问题或其他问题?
  • 不,它没有。请在下面查看我的评论。

标签: kubernetes kustomize


【解决方案1】:

在元数据中给他们不同的名字。你没有做一个新的,你只是覆盖了同一个。

【讨论】:

  • 不,我不想给他们起不同的名字。我只想将ns3 中的foo-user 绑定到foo-role。
  • 然后同时列出所有科目。你看到的对象就是你得到的对象。它不像 RPC 调用,它们是 REST 对象。
  • (您必须为此使用 rfc6902 补丁)
  • 如果我使用 rfc6902 补丁,是否只能列出我要添加的主题?
  • 当然,我猜。为什么不制作多个对象呢?这就是应该如何工作的。您可以拥有任意数量的绑定。
猜你喜欢
  • 2016-11-08
  • 1970-01-01
  • 2019-08-31
  • 1970-01-01
  • 2013-08-17
  • 1970-01-01
  • 2015-12-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多