Lab 12 - Helm & Kustomize¶
45 min Intermediate
Problem¶
The greeting service has to run in a dev and a prod environment with different settings. You'll deploy it both ways teams do in practice: with Kustomize overlays, then as a Helm release you can upgrade and roll back.
See Helm & Kustomize for the concepts.
Prerequisites¶
- An OpenShift cluster (or Kubernetes: see the tip below) and the
ocCLI - The
helmCLI, version 4. Install it withbrew install helmon macOS, or see the Helm install guide. -
A clone of the bootcamp repository:
Using plain Kubernetes?
Everything works on kind or minikube. Remove the components: lines from the overlays (they add an OpenShift Route), use kubectl in place of oc, and use kubectl port-forward in place of the Route URLs.
Part 1: Kustomize¶
-
Look at the layout, then render both overlays without applying them. What differs between dev and prod?
-
Create a project for each environment and deploy the matching overlay.
-
Call both environments through their Routes. Each should return its own greeting, and prod should have 3 pods.
-
Change the dev greeting in
kustomize/overlays/dev/kustomization.yaml. Before applying, preview the change withoc diff, then apply it. Why does the Deployment roll out new pods even though you only changed a ConfigMap value?Solution
oc diff -k kustomize/overlays/dev -n greeting-dev oc apply -k kustomize/overlays/dev -n greeting-dev oc rollout status deployment/greeting -n greeting-devconfigMapGeneratorappends a hash of the content to the ConfigMap name, for examplegreeting-config-cfm652bgbb. A new value produces a new name, which changes the Deployment's pod template, so Kubernetes rolls out new pods that read the new value. A hand-written ConfigMap wouldn't do this, and pods would keep the old environment variables until restarted. -
Your turn: create a new overlay,
kustomize/overlays/test, that runs 2 replicas, labels everythingenvironment: test, and greets withHello from test. Deploy it to agreeting-testproject.
Part 2: Helm¶
-
Check and render the chart locally. Nothing is created in the cluster yet.
-
Install the chart as a release named
greetingin a newgreeting-helmproject, with your own greeting. -
Upgrade the release to 2 replicas, look at the release history, and run the chart's test.
-
Roll back to the first revision and confirm the replica count. What revision number does the rollback create?
-
Upgrade to the production values file,
values-prod.yaml. It sets 3 replicas, more memory, and enables a ServiceMonitor for Prometheus, which you'll use in Lab 13.
Part 3 (optional): Let Argo CD deploy it¶
After you've done the Argo CD Lab, create an Application whose path is sample-app/kustomize/overlays/dev in your fork. Argo CD runs Kustomize for you, so you never run oc apply -k again. Promote a new image by changing newTag in the overlay and pushing the commit.
Cleanup¶
helm uninstall greeting -n greeting-helm
oc delete project greeting-dev greeting-prod greeting-test greeting-helm
About the image
The overlays and chart use ghcr.io/ibm-cloud-architecture/cloud-native-bootcamp/greeting:v1.1.0. To use the image you built in the Containers Lab instead, set images[].newName in an overlay, or --set image.repository=quay.io/<you>/greeting with Helm.