<p>I have a couple of overlays (dev, stg, prod) pulling data from multiple bases where each base contains a single service so that each overlay can pick and choose what services it needs. I generate the manifests from the dev/stg/prod directories.</p>
<p>A simplified version of my Kubernetes/Kustomize directory structure looks like this:</p>
<pre><code>├── base
│   ├── ServiceOne
│   │   ├── kustomization.yaml
│   │   └── service_one_config.yaml
│   ├── ServiceTwo
│   │   ├── kustomization.yaml
│   │   └── service_two_config.yaml
│   └── ConfigMap
│       ├── kustomization.yaml
│       └── config_map_constants.yaml
└── overlays
    ├── dev
    │   ├── kustomization.yaml
    │   └── dev_patch.yaml
    ├── stg
    │   ├── kustomization.yaml
    │   └── stg_patch.yaml
    └── prod
        ├── kustomization.yaml
        └── prod_patch.yaml
</code></pre>
<p>Under base/ConfigMap, config_map_constants.yaml file contains key/value pairs that are non-secrets:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    app: myApp
  name: global-config-map
  namespace: myNamespace
data:
  aws_region: &quot;us-west&quot;
  env_id: &quot;1234&quot;
</code></pre>
<p>If an overlay just needs a default value, it should reference the key/value pair as is, and if it needs a custom value, I would use a patch to override the value.</p>
<p>kustomization.yaml from base/ConfigMap looks like this and refers to ConfigMap as a resource:</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - config_map_constants.yaml
</code></pre>
<p>QUESTION: how do I reference &quot;aws_region&quot; in my overlays' yaml files so that I can retrieve the value?</p>
<p>For example, I want to be able to do something like this in base/ServiceOne/service_one_config.yaml:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: myApp
    aws_region: ../ConfigMap/${aws_region} #pseudo syntax
  name: service_one
spec:
  env_id: ../ConfigMap/${env_id} #pseudo syntax
</code></pre>
<p>I am able to build the ConfigMap and append it to my services but I am struggling to find how to reference its contents within other resources.</p>
<p>EDIT:
Kustomize version: v4.5.2</p>

<p>You can try using <a href="https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/replacements/" rel="nofollow noreferrer">https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/replacements/</a></p>
<p>For your scenario, if you want to reference the <code>aws-region</code> into your Service labels. You need to create a <code>replacement</code> file.</p>
<p><code>replacements/region.yaml</code></p>
<pre class="lang-yaml prettyprint-override"><code>source:
  kind: ConfigMap
  fieldPath: data.aws-region
targets:
  - select:
      kind: Service
      name: service_one
    fieldPaths:
      - metadata.labels.aws_region

</code></pre>
<p>And add it to your <code>kustomization.yaml</code></p>
<pre class="lang-yaml prettyprint-override"><code>replacements:
  - path: replacements/region.yaml
</code></pre>
<p>Kustomize output should be similar to this</p>
<pre class="lang-yaml prettyprint-override"><code>---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: myApp
    aws_region: us-west-1
  name: service_one
</code></pre>
