Skip to content

Recipes

Short patterns, each one an assembly of parts the earlier chapters proved. The file fragments are the deliverable; the notes say what to check after.

A debug overlay for your own machine

Production and staging are not the only places an application runs. A third overlay — small, personal, usually kept out of the shared repository or clearly named inside it — restates the app for your laptop:

namePrefix: dev-
replicas:
  - name: webhello
    count: 1
patches:
  - target:
      kind: Deployment
      name: webhello
    patch: |-
      - op: add
        path: /spec/template/spec/containers/0/env/-
        value: {name: LOG_LEVEL, value: debug}

This is staging's shape with the team fields removed (the lab's edit session in chapter 9 built nearly this file by command). Check: build it, diff against staging, and confirm the only differences are the ones a laptop wants.

The release bump

A release, in overlay terms, is one line: the image tag. Do it mechanically and let the diff review it:

$ cd app/overlays/production
$ kustomize edit set image webhello=webhello:1.3.0
$ kustomize build . > /tmp/new-production.yaml
$ diff /tmp/old-production.yaml /tmp/new-production.yaml

Expect exactly the tag line (and, if a digest is pinned, the digest) to move. Anything else in that diff is not part of your release.

One base, a folder per customer

Several near-identical deployments — one per site, tenant or customer — are overlays that differ only in name, labels and a literal or two:

overlays/
  site-north/   (namePrefix: north-, greeting literal)
  site-south/   (namePrefix: south-, greeting literal)

Each is a five-line kustomization over the same base, with behavior: merge (chapter 6) changing only its own literals. The discipline that keeps this honest: the customers' differences live in their overlays and nowhere else, so "which sites get the new base?" is answered by building all of them and diffing (chapter 10's loop).

A shared middle layer

Bases compose. If staging and production share a set of changes that a laptop overlay should not inherit — company labels, a standard annotation, a logging sidecar patch — put those in an intermediate overlay (overlays/common/) and let staging and production build on it rather than directly on the base. Three layers deep is normal; five is a smell. Each layer must still read as a list of differences from the one below it, or the stack has become the thing chapter 1 warned about: differences nobody can audit in one sitting.

Configuration that is not a Secret

A file every environment shares except for two keys is a base generator with a merge on top — the production pattern from chapter 6 exactly. Resist the shortcut of patching the generated ConfigMap's data: with a patch instead: the generator owns the contents, the hash is computed from them, and a patch that edits contents after generation is fighting the mechanism that keeps names and contents in step. Merge at the generator; patch resources that were written, not generated.

What is not here

Fetching a base from a remote repository (resources: - https://github.com/...) is a real kustomize feature with real uses — shared platform bases across teams — and real weight: a build then executes a fetch of someone else's files, so the base's owner and version become part of your supply chain. The lab did not exercise it (chapter 13 explains why, and what pinning discipline it demands), so it appears in this guide as a described pattern only, from the project's documentation.