<p>i have a base yaml and an overlay yaml and using "kustomize" i want to merge these two yaml. what happens with me is that on running kustomize build there comes an output but it is not expected why? because the kustomize instead of filling the custom information from the overlay yaml replaces the whole heading tag of the base with the overlay "containers" in my case. The intended behaviour that i need is the it should somehow fill in the missing information using the overlay yaml instead of replacement.</p>

<p>base yaml: </p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: temp
  labels:
    tier: temp
spec:
  containers:
  - name: temp
    image:  temp
    imagePullPolicy: Always
    command: temp
    args:
      temp
    envFrom:
    - configMapRef:
        name: temp
    volumeMounts:
  volumes:
</code></pre>

<p>overlay yaml:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: temp
  labels:
    tier: temp
spec:
  containers:
    volumeMounts:
    - name: temppathname
      mountPath: /temppath
  volumes:
  - name: temppathname
    hostPath:
      type: temp
      path: temppath

</code></pre>

<p>Expected result after kustomize build:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: temp
  labels:
    tier: temp
spec:
  containers:
  - name: temp
    image:  temp
    imagePullPolicy: Always
    command: temp
    args:
      ["sleep 9000"]
    envFrom:
    - configMapRef:
        name: temp
    volumeMounts:
    - name: temppathname
      mountPath: /temppath
  volumes:
  - name: temppathname
    hostPath:
      type: temp
      path: temppath
</code></pre>

<p>what i'm getting:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  labels:
    tier: temp
  name: temp
spec:
  containers:
    volumeMounts:
    - name: temppathname
      mountPath: /temppath
  volumes:
  - name: temppathname
    hostPath:
      type: temp
      path: temppath
</code></pre>

<p>In your <code>base.yaml</code> the value for the key <code>containers</code> is a sequence (node). In your <code>overlay.yaml</code> the value for the key <code>containers</code> is a mapping. Of course those two cannot be merged.</p>

<p>Not knowing kustomize at all, it seems logical that because those cannot be merged, the overlay replaces that whole sequence node with the mapping node. Your expectation that the mapping of the overlay is merged with a mapping that happens to be an item (in this case the only item) in the sequence of the base seems completely arbitrary. Which item would need to be taken if there had been multiple items? The first? The last? The last one before item five that is a mapping?</p>

<p>If your <code>overlay.yaml</code> looked like:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: temp
  labels:
    tier: temp
spec:
  containers:
  - volumeMounts:     # &lt; created a sequence item here by inserting an item indicator
    - name: temppathname
      mountPath: /temppath
  volumes:
  - name: temppathname
    hostPath:
      type: temp
      path: temppath
</code></pre>

<p>then I could understand your expectation (and maybe the above change can be applied to make it work, I don't have a way to test).</p>
