<p>I'm trying to use Kustomize but as a result I have wrong placeholder lines.</p>
<p>I have <code>base/deployment.yaml</code> like this:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app
  template:
    metadata:
      labels:
        app: app
    spec:
      containers:
        - image: IMAGE_PLACEHOLDER
          name: CONTAINER_NAME_PLACEHOLDER
</code></pre>
<p>And also <code>base/kustomization.yaml</code>:</p>
<pre><code>resources:
  - deployment.yaml
</code></pre>
<p>And also overlays/dev/kustomization.yaml:</p>
<pre><code>resources:
  - ../../base
commonLabels:
  app: myname
patchesStrategicMerge:
  - change_container_name.yaml
</code></pre>
<p>And <code>overlays/dev/change_container_name.yaml</code>:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: app
spec:
  template:
    spec:
      containers:
        - name: myname
          image: registry.mycompany.ru/project/app:VERSION
</code></pre>
<p>And as a result of running <code>kubectl kustomize ./overlays/dev</code> i see in my console something like this:</p>
<pre><code>...
containers:
      - image: registry.mycompany.ru/project/app:VERSION
        name: myname
        image: IMAGE_PLACEHOLDER #--- unwanted line
        name: CONTAINER_NAME_PLACEHOLDER #--- unwanted line
        ports:
        - containerPort: 80
</code></pre>
<p>How to fix this problem?</p>

Victoria Agafonova
<p>This isn't going to work the way you want: because <code>containers:</code> is a list, Kustomize uses the container name to identify which element you want to modify. Because the container name in your patch doesn't match an existing container name, you are <em>adding a new container</em> to the deployment. That's why you end up with:</p>
<pre><code>      containers:
      - image: registry.mycompany.ru/project/app:VERSION
        name: myname
      - image: IMAGE_PLACEHOLDER
        name: CONTAINER_NAME_PLACEHOLDER
</code></pre>
<p>I'm not sure what your motivation is here, but if you really want to modify the name of an existing container you can do that using a jsonpatch patch instead of a strategic merge patch. The patch might look like this:</p>
<pre><code>- op: replace
  path: /spec/template/spec/containers/0/name
  value: myname
</code></pre>
<p>And I would use it in a kustomization file like this:</p>
<pre><code>resources:
  - ../../base

commonLabels:
  app: myname

patches:
  - path: change_container_name.yaml
    target:
      kind: Deployment
      name: app
</code></pre>
<p>Given your examples, this would produce the following output:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: myname
  name: app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myname
  template:
    metadata:
      labels:
        app: myname
    spec:
      containers:
      - image: IMAGE_PLACEHOLDER
        name: myname
</code></pre>
<p>You could do the same thing with the image name, but you could <em>also</em> use an <a href="https://github.com/kubernetes-sigs/kustomize/blob/master/examples/transformerconfigs/README.md#images-transformer" rel="nofollow noreferrer">image transformer</a>:</p>
<pre><code>resources:
  - ../../base
commonLabels:
  app: myname

patches:
  - path: change_container_name.yaml
    target:
      kind: Deployment
      name: app

images:
  - name: IMAGE_PLACEHOLDER
    newName: registry.mycompany.ru/project/app
    newTag: VERSION
</code></pre>
<p>Which gets us:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: myname
  name: app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myname
  template:
    metadata:
      labels:
        app: myname
    spec:
      containers:
      - image: registry.mycompany.ru/project/app:VERSION
        name: myname
</code></pre>
