gpt4 book ai didi

kubernetes - ClusterRole 存在且无法导入当前版本?

转载 作者:行者123 更新时间:2023-12-04 13:11:06 25 4
gpt4 key购买 nike

我试图在两个不同命名空间的同一个集群中两次安装同一个图表。但是我收到此错误:

Error: rendered manifests contain a resource that already exists. Unable to continue with install: ClusterRole "nfs-provisioner" in namespace "" exists and cannot be imported into the current release: invalid ownership metadata; annotation validation error: key "meta.helm.sh/release-namespace" must equal "namespace2": current value is "namespace1"
据我了解,集群角色应该独立于命名空间,所以我发现这是矛盾的。我们正在使用 helm3

最佳答案

我决定提供一个社区 Wiki 答案,可以帮助其他面临类似问题的人。
我假设您想多次安装相同的图表,但出现以下错误:

Error: rendered manifests contain a resource that already exists. Unable to continue with install: ClusterRole "<CLUSTERROLE_NAME>" in namespace "" exists and cannot be imported into the current release: ...
首先,决定我们是否真的需要 ClusterRole 很重要而不是 Role .
我们可以在 Role and ClusterRole documentation 中找到:

If you want to define a role within a namespace, use a Role; if you want to define a role cluster-wide, use a ClusterRole.


其次,我们可以使用 ClusterRole 的变量名。而不是在模板中硬编码名称:
例如,而不是:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: clusterrole-1
...
尝试使用类似的东西:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ .Values.clusterrole.name }}
...
第三,我们可以使用 lookup函数和 if控制结构以跳过创建资源(如果资源已经存在)。
看一个简单的例子:
$ cat clusterrole-demo/values.yaml
clusterrole:
name: clusterrole-1

$ cat clusterrole-demo/templates/clusterrole.yaml
{{- if not (lookup "rbac.authorization.k8s.io/v1" "ClusterRole" "" .Values.clusterrole.name) }}

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ .Values.clusterrole.name }}
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- list
- watch
{{- end }}
在上面的例子中,如果 ClusterRole clusterrole-1已经存在,不会被创建。

关于kubernetes - ClusterRole 存在且无法导入当前版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65110332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com