Kustomize - “failed to find unique target for patch …”

I just start using kustomize. I have the following yaml files for customize:

ls -l ./kustomize/base/
816 Apr 18 21:25 deployment.yaml
110 Apr 18 21:31 kustomization.yaml
310 Apr 18 21:25 service.yaml

where deployment.yaml and service.yaml are generated files with jib and they are fine in running. And the content of the kustomization.yaml is the following:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:  
- service.yaml
- deployment.yaml  

And in another directory

ls -l ./kustomize/qa
133 Apr 18 21:33 kustomization.yaml
95 Apr 18 21:37 update-replicas.yaml

where

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- ../base

patchesStrategicMerge:
- update-replicas.yaml

and

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 2

After running “kustomize build ./kustomize/base”, I run

~/kustomize build ./kustomize/qa
Error: no matches for OriginalId ~G_~V_Deployment|~X|my-app; no matches for CurrentId ~G_~V_Deployment|~X|my-app; failed to find unique target for patch ~G_~V_Deployment|my-app

I have a look related files and don’t see any typo on the application name.

How to resolve this problem?

Cluster information:

Kubernetes version: 1.17.3
Cloud being used: (put bare-metal if not on a public cloud)
Installation method:
Host OS: Linuxmint 18.2
CNI and version:
CRI and version:

You can format your yaml by highlighting it and pressing Ctrl-Shift-C, it will make your output easier to read.

Can you please try changing the below,

from:

resources:

  • …/base

to:

bases:

  • …/base

Thanks for your input.

The change doesn’t change the outcome, unfortunately.

Same problem here. Did you find a solution?

No, to my knowledge.

In my case I found using patches instead of patchesJson6902 solved the problem. I don’t know why the more specific directives exist if they don’t work the same way.

1 Like

Just ran into this same issue. Your answer just saved me many more hours of googling. Thank you!

I’ve also created a stackoverflow question to ask about this. You might want to follow it if you’re interested.

Thanks Alex for the kind words – also, I posted an answer to your SO question with my findings.

I ran into same issue and had to use the fix mentioned in this bug - Undocumented change in patchesJson6902 handling from v2.1.0 and v3.0.x · Issue #1351 · kubernetes-sigs/kustomize · GitHub

Had to remove the namespace from the base yaml.

I had an error that looked almost like this:
error: accumulating resources: accumulation err=‘accumulating resources from ‘kube/anne’: ‘/home/anne/IdeaProjects/PlanYourProject/kube/anne’ must resolve to a file’: recursed accumulation of path ‘/home/anne/IdeaProjects/PlanYourProject/kube/anne’: no matches for Id apps_v1_Service|~X|pyp; failed to find unique target for patch apps_v1_Service|pyp

My solution was to change the apiVersion in the patch for my pyp service from apps/v1, to just v1.
Because the service was defined with apiVersion v1. Hope this helps someone :slight_smile:

  1. you have to create update-replicas.yaml in your base folder.
  2. put the filename also in base/kustomization.yaml under "resources: "

Here you can find a good tutorial:
Kustomize Tutorial With Instructions & Examples | Densify