<p>I have a kube-prometheus deployed to multiple environments using kustomize.</p>
<p>kube-prometheus is a base and each environment is an overlay.
Let's say I want to deploy dashboards to overlays, which means I need to deploy the same ConfigMaps and the same patch to each overlay.</p>
<p>Ideally, I want to avoid changing the base as it is declared outside of my repo and to keep things DRY and not to copy the same configs all over the place.</p>
<p>Is there a way to achieve this?</p>
<p>Folder structure:</p>
<pre><code>/base/
     /kube-prometheus/
/overlays/
     /qa/       &lt;--- 
     /dev/      &lt;--- I want to share resources+patches between those
     /staging/  &lt;---

</code></pre>

RedReaperKun
<p>The proper way to do this is using <strong>components</strong>.</p>
<p>Components can encapsulate both resources and patches together.
In my case, I wanted to add ConfigMaps (resource) and mount this ConfigMaps to my Deployment (patch) without repeating the patches.</p>
<p>So my overlay would look like this:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - ../../base/kube-prometheus/ # Base

components:
  - ../../components/grafana-aws-dashboards/ # Folder with kustomization.yaml that includes both resources and patches
</code></pre>
<p>And this is the component:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component

resources:
- grafana-dashboard-aws-apigateway.yaml
- grafana-dashboard-aws-auto-scaling.yaml
- grafana-dashboard-aws-ec2-jwillis.yaml
- grafana-dashboard-aws-ec2.yaml
- grafana-dashboard-aws-ecs.yaml
- grafana-dashboard-aws-elasticache-redis.yaml
- grafana-dashboard-aws-elb-application-load-balancer.yaml
- grafana-dashboard-aws-elb-classic-load-balancer.yaml
- grafana-dashboard-aws-lambda.yaml
- grafana-dashboard-aws-rds-os-metrics.yaml
- grafana-dashboard-aws-rds.yaml
- grafana-dashboard-aws-s3.yaml
- grafana-dashboard-aws-storagegateway.yaml

patchesStrategicMerge:
- grafana-mount-aws-dashboards.yaml
</code></pre>
<p>This approach is documented here:<br />
<a href="https://kubectl.docs.kubernetes.io/guides/config_management/components/" rel="noreferrer">https://kubectl.docs.kubernetes.io/guides/config_management/components/</a></p>
