Kustomize Problem Statement & Idealogy
Kustomise Problem Statement & Idealogy
-
What problems does Kustomise try to address.
-
We have three environments:
-
dev
-
stg
-
prod
-
-
We want to customise the deployment, so it behaves a little differently in each environment.
- The manifest is the following:
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 1 selector: matchLabels: component: nginx template: metadata: labels: component: nginx spec: containers: - name: nginx image: nginx -
For example, we want to change the amount of
replicasin thedevenvironment. -
How do we modify it on a per configuration basis.
-
A simple solution is to create three separate directories, one for each variation of the above yaml file.
-
stgdirectory would havereplicasset to2,prodwould be3etc. -
To push the changes out, run
kubectl apply -f dev/for all three environments. -
Not the most optimal or scaleable solution.
-
If create
service.yamlfile, this is needed to be copied to all directories.- Kustomise helps to customise individual environments, without replicating code.
-
-
-
Kustomise has two terms - base config and overlay.
-
baseconfig is identical across all environments.-
This also includes default values, which you can override later on.
-
An example config is the
nginxconfig listed above.
-
-
overlays- these allow us to customise behaviour on a per-environment basis.- An example of an overlay is:
spec: replicas: 1
- An example of an overlay is:
-
The above overlay would be
dev.- The overlay changes what is in the base config. In the above example, we focus on
replicas.
- The overlay changes what is in the base config. In the above example, we focus on
-
An overlay for
stgfor example:spec: replicas: 1
-
-
The
directorystructure is like so:-
k8s–>base/overlays-
Under
baseyou would have:-
kustomizaton.yaml -
nginx-depl.yaml -
service.yaml -
redis-depl.yaml
-
-
Under
overlaysyou have:-
dev–>kustomization.yamlandconfig-map.yaml -
stg–>kustomization.yamlandconfig-map.yaml -
prod–>kustomization.yamlandconfig-map.yaml
-
-
-
-
baseis shared across all environments.overlayis changes to specific environments. -
kustomise takes the
baseandoverlayand mixes them together to create the final manifest. -
kustomise comes built-in with
kubectl.- May want to install
kustomize cli, as the one that comes withkubectlis not the latest version.
- May want to install
-
With
kustomize, no need to learn a templating language likehelm.- Complex
helmcharts are difficult to read because of the templating system.
- Complex
kustomizeisyamlonly.