5

I have a kube-prometheus deployed to multiple environments using kustomize.

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.

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.

Is there a way to achieve this?

Folder structure:

/base/
     /kube-prometheus/
/overlays/
     /qa/       <--- 
     /dev/      <--- I want to share resources+patches between those
     /staging/  <---

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
RedReaperKun
  • 121
  • 1
  • 9

2 Answers2

7

The proper way to do this is using components.

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.

So my overlay would look like this:

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

And this is the component:

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

This approach is documented here:
https://kubectl.docs.kubernetes.io/guides/config_management/components/

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
RedReaperKun
  • 121
  • 1
  • 9
  • afaik components operate on the accumulated resources *before* changes from the caller directory have been applied. This can be a gotcha and sometimes makes components not practical. – The Fool Jun 07 '23 at 21:56
0

In your main kustomization, or some top-level overlay, you should be able to call for a common folder or repository.

Have you tried something like this:

resources:
  - github.com/project/repo?ref=x.y.z

If this doesn't answer your question, could you please edit your post and give us some context?

SYN
  • 4,476
  • 1
  • 20
  • 22
  • Yep, of course I need to reference my base and additional resources, the point is that I want to have kustomization file that will create configmaps and patch deployment to mount them for every overlay I want. – RedReaperKun Dec 05 '21 at 10:08