现在,我必须在不同的命名空间中安装多个 Helm Chart 才能使我的产品正常工作。我正在尝试创建一个超级舵图,我计划在其中添加舵图(我的工具,如上所述)并一次性安装它们。我的问题是,由于这些工具位于不同的命名空间中,我不确定在哪里指定我想要安装特定依赖项(图表)的命名空间键。例如如果下面是我的超级舵图的 Charts.yaml
dependencies:
- name: first_chart
version: 1.2.3
repository: https://firstchart.repo
- name: second_chart
version: 1.5.6
repository: https://secondchart.repo
我希望我的第一个图表安装在命名空间 foo 中,第二个图表安装在命名空间 bar 中。
我正在考虑使用条件,但我相信条件只会采用布尔值作为值。
我偶然发现了这个链接 (https://github.com/helm/helm/issues/2060),它说我们可以在 Helm 3 中做到这一点,但主要是关于如何在不同命名空间之间保留版本。它没有具体回答我的问题。
没有内置方法可以使用纯 Helm 来执行此操作,但可以使用 helmfile。
您的示例为
helmfile.yaml
:
releases:
- name: chart1 # name of the release (helm install <...> first_chart)
chart: repo1/first_chart
version: 1.2.3
namespace: foo
- name: chart2
chart: repo2/second_chart
version: 1.5.6
namespace: bar
# in case you want helmfile to automatically update repos
repositories:
- name: repo1
url: https://firstchart.repo
- name: repo2
url: https://secondchart.repo
然后,运行:
helmfile sync
=> 在所有版本上运行 helm install/upgrade
,或者 helmfile apply
=> 与同步相同,但首先进行比较以仅升级/安装已更改的版本helmfile 还有更多内容,但这就是要点。
PS:如果您对值感到困惑,或者想要拥有类似于处理伞图值的方式,请查看 helmfile:直观处理值的简单技巧
我使用 ArgoCD 的 App of Apps 集群 bootstrapping 模型为我的集群解决了这个问题。当然,这需要ArgoCD安装集群。 但是,由于许多与此答案无关的原因,我强烈鼓励安装 ArgoCD,无论引导功能是否容易。
假设 ArgoCD 已就位,该结构是一个单独的 Helm 图表,其中包含将通过 Argo 的 Application CRD 部署和管理的每个子图表的模板。您会注意到 CRD 中有一个定义,
spec.destination.namespace
,它控制图表的部署位置。
管理我的证书管理器图表部署到
cert-manager
命名空间的示例应用程序模板如下所示:
{{- if .Values.certManager.enabled }}
# ref: https://argo-cd.readthedocs.io/en/stable/operator-manual/declarative-setup/#applications
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: cert-manager
# You'll usually want to add your resources to the argocd namespace.
namespace: argocd
# Add a this finalizer ONLY if you want these to cascade delete.
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
# The project the application belongs to.
project: cluster-configs
# Source of the application manifests
source:
repoURL: https://github.com/yourOrg/Helm
targetRevision: {{ .Values.targetRevision }}
path: charts/cert-manager-chart
# helm specific config
helm:
# Helm values files for overriding values in the helm chart
# The path is relative to the spec.source.path directory defined above
valueFiles:
{{- range .Values.certManager.valueFiles }}
- {{ . }}
{{- end }}
# Optional Helm version to template with. If omitted it will fall back to look at the 'apiVersion' in Chart.yaml
# and decide which Helm binary to use automatically. This field can be either 'v2' or 'v3'.
version: v3
# Destination cluster and namespace to deploy the application
destination:
server: https://kubernetes.default.svc
namespace: cert-manager
{{- end }}
此父图表对应的
values.yaml
文件可能类似于以下内容,并指定了子图表目录中所需值文件的路径。
targetRevision: v1.11.0
certManager:
enabled: true
valueFiles:
- "values.yaml"
clusterAutoScaler:
valueFiles:
- "envs/dev-account/saas/values.yaml"
clusterResourceLimits:
valueFiles:
- "values.yaml"
externalDns:
valueFiles:
- "envs/dev-account/saas/values.yaml"
ingressNginx:
enabled: true
valueFiles:
- "values.yaml"
下面是我的应用程序目录中的一个应用程序的屏幕截图,用于完成示例。