Flux CD与Kustomize Kind: Component不兼容问题求助
问题描述
目录结构
├───base │ └───redis │ kustomization.yaml │ release.yaml │ ├───components │ └───target-namespace │ kustomization.yaml │ └───prod └───redis kustomization.yaml
Redis覆盖配置
prod/redis/kustomization.yaml
kind: Kustomization namespace: flux-system resources: - ../../base/redis components: - ../base/components/target-namespace
components/target-namespace/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1alpha1 kind: Component patches: - patch: |- apiVersion: helm.toolkit.fluxcd.io/v2beta1 kind: HelmRelease metadata: name: not-used spec: targetNamespace: default target: kind: HelmRelease
本地与Flux执行差异
- 本地执行命令:
构建正常。build .\prod\redis\ - 推送至Flux CD后出现错误:
/components/target-namespace is a directory': expected kind != 'Component'
问题原因与解决办法
这个问题出在组件路径引用错误,本地Kustomize对路径的容错性或解析逻辑和Flux存在差异,导致本地能正常构建但Flux报错。
你当前在prod/redis/kustomization.yaml里写的组件路径../base/components/target-namespace是错误的——components目录和base、prod是同级关系,正确的相对路径应该是../../components/target-namespace。
修改后的prod/redis/kustomization.yaml:
kind: Kustomization namespace: flux-system resources: - ../../base/redis components: - ../../components/target-namespace
另外,也可以直接使用基于Git仓库根目录的绝对路径引用组件,这种方式更不易出错:
components: - /components/target-namespace
修改后重新推送至Flux CD即可解决该问题。
内容的提问来源于stack exchange,提问作者Quies
相关产品推荐
相关产品推荐

