fluxcd

flux kustomize build failed - resource with an already registered id


Here is the folder structure for my flux repo

└── clusters
  └── homelab
    ├── default
    │   ├── deployment.yaml
    └── flux-system
        ├── gotk-components.yaml
        ├── gotk-sync.yaml
        └── kustomization.yaml

And when I pushed the deployment.yaml file and checked the deployment using flux get kustomizations --watch

I got the following error;

NAME        REVISION            SUSPENDED   READY   MESSAGE                                                                                                                                                                                                                                                                                                                                  
flux-system main@sha1:58009946  False       False   kustomize build failed: accumulating resources: accumulation err='merging resources from './default/deployment.yaml': may not add resource with an already registered id: Deployment.v1.apps/spring-web.[noNs]': must build at directory: '/tmp/kustomization-308548873/clusters/homelab/default/deployment.yaml': file is not directory

I've tried deleting the kustomization using flux delete kustomization flux-system but it didn't go anything at it still remains in the output.

Also can't see any deployment in k8s under that name when checking kubectl get deployments -A


Solution

  • You need to have a kustomization.yaml file in the default directory.

    └── clusters
      └── homelab
        ├── default
        │   ├── deployment.yaml
        │   ├── kustomization.yaml
        └── flux-system
            ├── gotk-components.yaml
            ├── gotk-sync.yaml
            └── kustomization.yaml
    

    Inside the kustomization.yaml, we should include the deployment.yaml file, as shown below:

    apiVersion: kustomize.config.k8s.io/v1beta1
    kind: Kustomization
    resources:
      - deployment.yaml