<p>I am trying to deploy a K8s application using Kustomize. Up to now I have done simple implementations where we have a few of the K8s files such as <code>ingress.yaml</code> with something like the following:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingressname
  namespace: namespace
  labels:
    app: appname  
spec:
  tls:
    - hosts:
        - $(variable1) 
      secretName: $(variable2)-tls
</code></pre>
<p>Under my <code>overlays</code> directory for each environment, I then have another <code>kustomize.yaml</code> which gives the values in a configmap:</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- path

configMapGenerator:
- behavior: merge
  literals:
  - variable1=foo
  - variable2=bar
  name: configmapname
images:
- name: imagename
  newName: registryurl
</code></pre>
<p>This works well, but now I need to do something more complicated. Say for example I have multiple ingress. Instead of creating multiple base ingress yaml files, how can I have one base yaml file that creates every ingress based on the values in my overlay file? Is that possible?</p>

<p>Kustomize isn't a templating system and doesn't do variable substitution. It <em>can</em> perform a variety of YAML patching tricks, so one option you have is to start with a base manifest like this:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingressname
spec:
  tls:
    - hosts: []
      secretName:
</code></pre>
<p>And then patch it in your <code>kustomization.yaml</code> files:</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - ../base

patches:
  - target:
      kind: Ingress
      name: ingressname
    patch: |
      - op: replace
        path: /spec/tls
        value:
          - hosts:
              - host1.example.com
            secretName: host1-tls
</code></pre>
<p>What I've shown here works well if you have an application consisting of a single Ingress and you want to produce multiple variants (maybe one per cluster, or per namespace, or something). That is, you have:</p>
<ul>
<li>A Deployment</li>
<li>A Service</li>
<li>An Ingress</li>
<li>(etc.)</li>
</ul>
<p>Then you would have one directory for each variant of the app, giving you a layout something like:</p>
<pre><code>.
├── base
│   ├── deployment.yaml
│   ├── ingress.yaml
│   ├── kustomization.yaml
│   └── service.yaml
└── overlays
    ├── variant1
    │   └── kustomization.yaml
    └── variant2
        └── kustomization.yaml
</code></pre>
<p>If your application has <em>multiple</em> Ingress resources, and you want to apply the same patch to all of them, <a href="https://github.com/kubernetes-sigs/kustomize/blob/master/examples/patchMultipleObjects.md" rel="nofollow noreferrer">Kustomize can do that</a>. If you were to modify the patch in your <code>kustomization.yaml</code> so that it looks like this instead:</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - ../base

patches:
  - target:
      kind: Ingress
      name: &quot;.*&quot;
    patch: |
      - op: replace
        path: /spec/tls
        value:
          - hosts:
              - host1.example.com
            secretName: host1-tls
</code></pre>
<p>This would apply the same patch to all matching Ingress resources (which is &quot;all of them&quot;, in this case, because we used <code>.*</code> as our match expression).</p>
