<p>When using Istio with Kubernetes, a number of different manifests require the same environment-specific values. For example, the host address is required by both the Gateway (under <code>spec/servers/hosts</code>) and VirtualService (under <code>spec/hosts)</code>. The typical approach to changing the address for different environments is to apply Kustomize patches. Is it possible to use a single patch to transform/insert the value into each manifest that needs it, or somehow maintain just one copy of the address that gets inserted where needed? The alternative is having to maintain multiple patch files with the same host address, and I would like to avoid duplication.</p>
<pre><code>---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: foo
spec:
  selector:
    istio: bar
  servers:
    - port:
        number: 443
        name: https
        protocol: HTTPS
      tls:
        mode: SIMPLE
        credentialName: secret
      hosts:
        - test.acme.com

---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: bazz
spec:
  hosts:
    - test.acme.com
  gateways:
    - foo
  http:
    - match:
      - uri:
          prefix: /api/v1
      route:
        - destination:
            host: blarg
            port:
              number: 80

</code></pre>

<p>This isn't going to be possible with just Kustomize other than by using multiple patches. Because you're looking to change the value in objects of different types, this can't be done with a single patch. So you could do this:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- manifests.yaml

patches:
  - target:
      kind: Gateway
      name: foo
    patch: |
      - op: replace
        path: /spec/servers/0/hosts/0
        value: foo.acme.com
  - target:
      kind: VirtualService
      name: bazz
    patch: |
      - op: replace
        path: /spec/hosts/0
        value: foo.acme.com
</code></pre>
<p>If you find you need to do this frequently (maybe you have a bunch of similar services), you could move the manifests into a helm chart and then <a href="https://github.com/kubernetes-sigs/kustomize/blob/master/examples/chart.md" rel="nofollow noreferrer">inflate that with kustomize</a>.</p>
