<p>I am interested in using YAML anchors for a list of objects. I have a Kubernetes pod manifest which contains a container list. I am trying to build this with kustomize, but I can't  find the right syntax.</p>
<p>So, I think this looks the most correct.</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata: { name: anchor-test }
spec:
  containers:
  - &amp;foo
    name: foo
    image: traefik/whoami
    ports: [ containerPort: 80 ]
  - &lt;&lt;: *foo
    name: bar
</code></pre>
<p>But kustomize is throwing this error:</p>
<pre class="lang-yaml prettyprint-override"><code>Error: map[string]interface {}{&quot;apiVersion&quot;:&quot;v1&quot;, &quot;kind&quot;:&quot;Pod&quot;, &quot;metadata&quot;:map[string]interface {}{&quot;name&quot;:&quot;anchor-test&quot;}, &quot;spec&quot;:map[string]interface {}{&quot;containers&quot;:[]interface {}{map[string]interface {}{&quot;image&quot;:&quot;traefik/whoami&quot;, &quot;name&quot;:&quot;foo&quot;, &quot;ports&quot;:[]interface {}{map[string]interface {}{&quot;containerPort&quot;:80}}}, map[interface {}]interface {}{&quot;image&quot;:&quot;traefik/whoami&quot;, &quot;name&quot;:&quot;bar&quot;, &quot;ports&quot;:[]interface {}{map[string]interface {}{&quot;containerPort&quot;:80}}}}}}: 
json: unsupported type: map[interface {}]interface {}
</code></pre>

The Fool
<p>So, this problem is specific to <code>kustomize</code>. It works with <code>kubectl apply -f</code>. That means the YAML is actually valid like this. It can be tested with <a href="http://www.yamllint.com/" rel="nofollow noreferrer">http://www.yamllint.com/</a>.</p>
<p>So for the time being, this is not possible with <code>kustomize</code>. There are some issues on GitHub around this.</p>
<ul>
<li><a href="https://github.com/kubernetes-sigs/kustomize/issues/4144" rel="nofollow noreferrer">https://github.com/kubernetes-sigs/kustomize/issues/4144</a></li>
<li><a href="https://github.com/kubernetes-sigs/kustomize/issues/3675" rel="nofollow noreferrer">https://github.com/kubernetes-sigs/kustomize/issues/3675</a></li>
</ul>
