You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

咨询ArgoCD多源配置下加载其他Git仓库templates目录的方案

问题解答

可以实现,但无法直接将外部Git仓库的templates目录作为Helm的模板目录使用,以下是两种可行方案:

方案1:通过Helm额外文件+模板引用实现

将外部仓库中的模板文件作为额外资源引入,再在主Chart的模板逻辑中调用。ArgoCD多源配置示例:

apiVersion: argoproj.io/v1alpha1
kind: Application
spec:
  sources:
  # 主Helm Chart源
  - repoURL: 'https://prometheus-community.github.io/helm-charts'
    chart: prometheus
    targetRevision: 15.7.1
    helm:
      extraFiles:
      - $templates/templates/custom-deployment.yaml
      # 也可将外部模板路径通过values传给主Chart,由主模板自行加载
      values: |
        extraTemplates: $templates/templates/
  # 存放额外模板的Git仓库
  - repoURL: 'https://git.example.com/org/extra-templates.git'
    targetRevision: dev
    ref: templates

这种方式需要主Chart的模板支持引用外部传入的文件,比如使用Helm的tpl或template函数渲染额外模板。

方案2:用Kustomize合并资源

如果不需要Helm渲染额外模板,仅需部署外部仓库中的K8s清单,可借助Kustomize将Helm渲染后的资源与外部清单合并:

apiVersion: argoproj.io/v1alpha1
kind: Application
spec:
  sources:
  # 主Helm Chart源
  - repoURL: 'https://prometheus-community.github.io/helm-charts'
    chart: prometheus
    targetRevision: 15.7.1
    ref: helm-chart
  # 存放额外模板的Git仓库
  - repoURL: 'https://git.example.com/org/extra-templates.git'
    targetRevision: dev
    ref: extra-manifests
  # Kustomize配置源,用于合并两个源的内容
  - repoURL: 'https://git.example.com/org/kustomize-config.git'
    targetRevision: dev
    path: ./
    kustomize:
      patches:
      - target:
          kind: Deployment
        path: $extra-manifests/templates/custom-patch.yaml

关键提醒

Helm的模板加载逻辑基于本地Chart结构,无法直接跨Git仓库加载templates目录。如果必须用外部模板进行Helm渲染,建议将外部仓库打包成子Chart,在主Chart中添加依赖引入,或者将外部模板合并到主Chart的templates目录下。

内容的提问来源于stack exchange,提问作者laimison

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 05:36:07