kustomize — up and running in 5 mins

Understanding the concept of overlay environments and configuration management using kustomize in local environment.

Ahmedulde
2 min readSep 9, 2020

--

  1. Install Kustomize

For mac users you can use homebrew. For any other OS you can refer the instructions on the kustomize.io

brew install kustomize

2. Build Manifests and Overlay structure

To maintain a consistent desired state of your kubernetes environments on git it is recommended to use the folder structure as shown below:

.
└── kubernetes-manifests
├── base
│ ├── guestbook-backend.deployment.yaml
│ ├── guestbook-backend.service.yaml
│ ├── guestbook-frontend.deployment.yaml
│ ├── guestbook-frontend.service.yaml
│ ├── guestbook-mongodb.deployment.yaml
│ ├── guestbook-mongodb.service.yaml
│ └── kustomization.yaml
└── overlays
├── dev
│ ├── guestbook-frontend.deployment-patch.yaml
│ └── kustomization.yaml
└── prod
├── guestbook-frontend.deployment-patch.yaml
├── guestbook-frontend.service-patch.yaml
└── kustomization.yaml

base folder contains the base kubernetes manifests file.

overlays folder contains additional folders per environment. In the environment folder you need to create a patch file and kustomization.yaml file. The patch file includes the modifications on top of base files and kustomization.yaml file points to the base folder as a reference to apply these patches on base files.

For example, lets consider the file guestbook-frontend.deployment.yaml

The base folder for this file includes a simple deployment manifest with no environment variables called “ENVIRONMENT”. The value of this env variable can be dev or prod.

Instead of duplicating the file and manually editing the file for 2 different environments you can create 2 folders under overlays folder and include a patch file which includes these changes along with a supporting kustomization file.

3. Build and Run

Run the commands below to dynamically generate new files per env:

cd kubernetes-manifests/overlays/dev/
kustomize build .

The output of the build command can be used with kubectl to apply to your cluster. You can refer the sample files as shown on the reference repo below.

Reference Code:

https://github.com/ahmedulde7/guestbook-deploy

--

--

Ahmedulde

Trusted Advisor, Mentor — Cloud and Devops SME