使用ApplicationSet与Application类型时,应用未部署至目标集群
在prod集群(EKS 2.21)运行ArgoCD 2.3.3,期望通过ApplicationSet将应用部署到staging集群(EKS 2.24),但部署Prometheus时失败,ArgoCD UI提示“未找到资源”。目标是在prod集群创建Application CRD,在staging集群部署Prometheus资源。
环境信息
- prod集群:EKS 2.21,运行ArgoCD 2.3.3
- staging集群:EKS 2.24,未部署ArgoCD CRDs
使用的ApplicationSet配置
apiVersion: argoproj.io/v1alpha1 kind: ApplicationSet metadata: name: myapplicationset namespace: argocd spec: generators: - git: repoURL: myrepo revision: main directories: - path: argocd/applications/* template: metadata: name: '{{path.basenameNormalized}}' namespace: argocd spec: project: "myproject" source: repoURL: myrepoURL targetRevision: main path: '{{path}}' destination: name: staging namespace: '{{path.basenameNormalized}}' syncPolicy: automated: prune: true selfHeal: true syncOptions: - CreateNamespace=true
原Prometheus配置(部署失败)
Git仓库argocd/applications/prometheus/prometheus.yaml内容:
apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: prometheus spec: project: myproject source: chart: prometheus repoURL: https://prometheus-community.github.io/helm-charts targetRevision: 14.9.2 helm: releaseName: prometheus destination: name: staging namespace: prometheus
替换后的配置(部署成功)
将上述文件替换为Chart.yaml后部署正常:
apiVersion: v2 name: prometheus type: application version: 14.9.2 appVersion: "14.9.2" dependencies: - name: prometheus version: 14.9.2 repository: https://prometheus-community.github.io/helm-charts
疑问
argocd/applications/下其他包含Chart.yaml或原生Kubernetes清单的目录均可正常工作。想知道为什么用Application清单无法部署,遗漏了什么?
问题核心是你混淆了ApplicationSet的工作逻辑和资源同步的目标:
ApplicationSet的同步逻辑误解
你的ApplicationSet配置中,source.path: '{{path}}'指向了argocd/applications/prometheus/目录,ArgoCD会直接把该目录下的所有Kubernetes资源同步到staging集群。你放入的是ApplicationCRD定义,这意味着ArgoCD试图在staging集群创建这个Application资源——但staging集群没有安装ArgoCD的CRDs,自然会提示“未找到资源”(argoproj.io/v1alpha1/Application这个CRD不存在)。Chart.yaml能成功的原因
当目录下是Chart.yaml(Helm依赖定义)时,ArgoCD会将其识别为一个Helm应用:拉取依赖的Prometheus chart,解析出标准Kubernetes资源(Deployment、Service、ConfigMap等),再同步到staging集群。这些都是原生Kubernetes资源,不需要ArgoCD CRDs就能被集群识别。正确的做法:分离Application定义与应用资源
ApplicationSet的作用是在prod集群的ArgoCD命名空间下批量生成Application资源,而不是把Application定义同步到目标集群。你需要调整两种方式之一:- 方式一:修改ApplicationSet模板
直接在ApplicationSet模板中配置Helm源,让它生成指向Prometheus chart的Application,不需要在Git目录中放Application定义:# 调整后的ApplicationSet spec.template.spec.source source: repoURL: https://prometheus-community.github.io/helm-charts targetRevision: 14.9.2 chart: prometheus helm: releaseName: '{{path.basenameNormalized}}' - 方式二:调整Git目录内容
把prometheus.yaml换成Prometheus的Helm values文件,然后在ApplicationSet模板中配置helm.valuesFiles指向该文件,让ArgoCD基于values文件拉取Helm chart并部署原生资源。
- 方式一:修改ApplicationSet模板
内容的提问来源于stack exchange,提问作者dstarostka

