Overlays
Overlays
-
Kustomise allows us to take a base Kubernetes config and customise it on a per-environment basis.
- Tweak on a
dev,stgandprod.
- Tweak on a
-
In
kustomize, thek8s/basedirectory is what is applied to everything.- Then in the
k8s/overlaysdirectory, this will have directories containingdev,stgandprodwith their ownkustomization.yamlfiles andconfig-map.yaml.
- Then in the
- The base
kustomizationfile looks like this: ``` resources:- nginx-depl.yaml
- service.yaml
- redis-depl.yaml ```
- The base
nginx-depl.yamlfile looks like this:apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 1 - An example overlay of
/dev/kustomization: ``` bases:- ../../base
patch: |- - op: replace path: /spec/replicas value: 2
* We update the value of `replicas` in the above to a value of `2`.
* You can have new configs in your `overlays` set of directories, that weren't defined in the base config.
* For example under `k8s/overlays/prod`, you can have these files:
kustomization.yaml config-map.yaml grafana-depl.yaml
* The `grafana-depl.yaml` doesn't exist in the base directory.
* You can add as many brand new resources as you want in an environment specific directory.
* The above `grafana-depl.yaml` would be imported using the following:
prod/kustomization.yaml
bases:
- ../../base
resources:
- grafana-depl.yaml
patch: |- - op: replace path: /spec/replicas value: 2 ```
-
Kustomise doesn’t force you into a specific directory structure.
-
No need to place everything into the
basedirectory. The sub-directories also do not matter.