RedReaperKun
RedReaperKun

Reputation: 201

How to share resources/patches with multiple overlays using kustomize?

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/  <---

Upvotes: 8

Views: 9400

Answers (2)

RedReaperKun
RedReaperKun

Reputation: 201

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/

Upvotes: 11

SYN
SYN

Reputation: 5032

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?

Upvotes: 0

Related Questions