Skip to the content.

Kustomize

Overview

The value proposition

Prerequisites

Installation

If not already installed with kubectl (run kubectl version to check), the easiest method of installation is via downloading a pre-compiled binary. The following will download and install the binary in a Linux Bash shell:

curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"  | bash

Description (kustomization.yaml)

resources:
  - <Path or URL>
  - <Path or URL>
nameSuffix: -prod
labels:
  businessUnit: OIM
kustomize/
   ├── base/
   │   ├── kustomization.yaml
   │   ├── deployment.yaml
   │   └── service.yaml
   └── overlays/
      └── uat/
          ├── kustomization.yaml
          ├── deployment_patch.yaml
          ├── service_patch.yaml
          └── ingress.yaml
      └── prod/
          ├── kustomization.yaml
          ├── deployment_patch.yaml
          ├── service_patch.yaml
          └── ingress.yaml

References:

Self-paced Kustomize tutorial

Prerequisites

kubectl commands for testing your configuration is set up:

kubectl config
kubectl config view
kubectl config current-context
kubectl config use-context <cluster-name>
kubectl cluster-info
kubectl get namespaces

References:

Step 0 - Intro

  1. Clone the following Git repository and cd into it: https://github.com/dbca-wa/kustomize-tutorial
  2. Run git checkout 00-intro
  3. Run kubectl kustomize overlays/uat, noting the YAML output.
  4. Run kubectl apply -k overlays/uat and watch the default namespace on the cluster, noting the created Deployment workload (nginx-deployment).
  5. Run kubectl delete -k overlays/uat to clean up the workload.
  6. Run kubectl apply -k overlays/prod to review the Deployment workload and note differences from the UAT one (tagged image version, resource request).
  7. Run kubectl delete -k overlays/prod to clean up.

Learning outcomes:

Step 1 - Refinements

  1. Run git checkout 01-refinements
  2. Run kubectl apply -k overlays/uat and watch the deployment resource start, having the -uat name suffix.
  3. Run kubectl apply -k overlays/prod, and note the difference in resource name.
  4. Take a look at the configuration of each resource and note differences.
  5. Clean up the resources.

Learning outcomes:

Step 2 - Service & label selectors

  1. Run git checkout 02-service
  2. Run kubectl apply -k overlays/uat and then kubectl apply -k overlays/prod.
  3. Examine the created deployments and services, noting the different label selectors that have been added to each resource (app, variant).
  4. Clean up the resources.

Learning outcomes:

Step 3 - Secret values

  1. Run git checkout 03-secrets
  2. Inside the overlays/uat directory, create a .env file containing the line: SECRET_VALUE=uat_secret-value
  3. Run kubectl apply -k overlays/uat and note the opaque secret that has been created along with the deployment and service.
  4. Start a shell session in the Nginx workload and run echo $SECRET_VALUE to confirm that the value is present as an environment variable.
  5. Repeat the steps above for the prod overlay, if desired.
  6. Clean up the resources.

Learning outcomes: