Kustomize Lab💣
Lab Overview💣
In this lab we use
kustomize
CLI tool for templating kubernetes.yaml
files, but first we will build out the directory structure and populate the necessary files.
Finally, we will compare the files that thekustomize
tool generated to understand howkustomize
is implemented
Kustomize💣
Lab💣
-
Verify kustomize is installed
kustomize version which kustomize
NOTE for Ubuntu users (if kustomize was installed via snap you’ll see errors, so let’s verify
The which command tells you the path where the kustomize cli tool is installed, if you see snap in the path, uninstall it and reinstall using the directions on this page -
Create the file structure
cd ~/Desktop/configlabs mkdir -p sample-app/base mkdir -p sample-app/overlays/development mkdir -p sample-app/overlays/production
-
Create the base deployment yaml and open to edit
vi sample-app/base/deployment.yaml
-
Add base pod to the file and save
apiVersion: apps/v1 kind: Deployment metadata: name: hello-world spec: replicas: 1 selector: matchLabels: app: hello-world template: metadata: labels: app: hello-world spec: containers: - name: hello-world image: nginx resources: limits: memory: "128Mi" cpu: "500m" ports: - containerPort: 80
-
Create the base kustomization.yaml and open to edit
vi sample-app/base/kustomization.yaml
-
Add the following contents and save
# Specifies the files to include when kustomize builds the application resources: - deployment.yaml
Create an overlay file and open to edit
vi sample-app/overlays/development/replica_count.yaml
-
Add the following contents and save
# Overlay to increase the replicaCount apiVersion: apps/v1 kind: Deployment metadata: name: hello-world spec: replicas: 3
-
Create an overlay kustomization file and open to edit
vi sample-app/overlays/development/kustomization.yaml
-
Add the following contents
# Specifies the base files bases: - ../../base # Specifies overrides to the base files patches: - replica_count.yaml
-
Generate Kustomize output
kustomize build sample-app/overlays/development cat sample-app/base/deployment.yaml
Compare the 2 outputs and notice the replicaCount of 3 was overlaid onto the base file
-
Generate a production deployment with kustomize
Create the
kustomization.yaml
andreplica_count.yaml
for production environmentAdd the following contentsvi sample-app/overlays/production/kustomization.yaml
bases: - ../../base patches: - replica_count.yaml
Add the following contentsvi sample-app/overlays/production/replica_count.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: hello-world spec: replicas: 200
Now create the deployment file for our production environment💣
-
This should spit the following out to the terminal:
kustomize build sample-app/overlays/production
apiVersion: apps/v1 kind: Deployment metadata: name: hello-world spec: replicas: 200 selector: matchLabels: app: hello-world template: metadata: labels: app: hello-world spec: containers: - image: nginx name: hello-world ports: - containerPort: 80 resources: limits: cpu: 500m memory: 128Mi