Skip to content

Your First Build

Outcome: the lab's base built, its output read line by line, and the three things the build did that you did not write — a hash on two names, and references rewritten to match — pointed out in the output where they happened.

The application

The lab's fixture is webhello, a small invented web service: one Deployment, one Service, a settings file, one configuration value, one token. It lives in kustomize-lab/app/:

app/
  base/
    deployment.yaml
    service.yaml
    settings.conf
    kustomization.yaml
  overlays/
    staging/       (chapter 5)
    production/    (chapters 5, 7, 8)
    broken-patch/  (chapter 14's first failure)
    broken-resource/ (chapter 14's second)

The base's kustomization is the whole recipe (transcript t01):

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - deployment.yaml
  - service.yaml
configMapGenerator:
  - name: webhello-config
    files:
      - settings.conf
    literals:
      - greeting=Hello from the base
secretGenerator:
  - name: webhello-secrets
    literals:
      - greeting-token=base-token-1234

Read it as a sentence: gather these two resources; also generate a ConfigMap named webhello-config holding a file and a literal; also generate a Secret named webhello-secrets holding one literal. The Deployment (t01) is plain Kubernetes YAML — image webhello:1.0.0, two replicas, an environment variable named GREETING holding the honest placeholder PLACEHOLDER (chapter 8 replaces it), a token pulled from the Secret by name, and the ConfigMap mounted as files at /etc/webhello.

And the token, before we go further, is invented: base-token-1234 is the lab talking to itself, chosen so chapter 6 can decode it in public. Rule 2 from chapter 1 applies to your bases with real teeth — a literal in a file you commit is a published value.

The build

$ kustomize build app/base

One command, and the whole application prints as a single YAML stream (transcript t02). Three things in it reward a close read.

The ConfigMap was assembled. Its data: holds settings.conf — the file's contents, verbatim, indented into place — beside the literal greeting: Hello from the base. Nobody pasted or indented anything; the generator did it at build time, and will redo it at every build, from the file as it stands then.

Two names grew suffixes. The ConfigMap is named webhello-config-t9599k79c5 and the Secret webhello-secrets-b955cdg665. The tails are hashes of the contents — chapter 6 spends itself on why — and the Deployment's references were rewritten to the suffixed names automatically: the volume mount points at webhello-config-t9599k79c5, the token's secretKeyRef at webhello-secrets-b955cdg665. A build never leaves a dangling reference to a name it renamed; that guarantee is half the reason the tool exists.

The Secret's value is base64. greeting-token prints as YmFzZS10b2tlbi0xMjM0, which is Kubernetes' own convention for Secret data — and, decoded in chapter 6, exactly the string that went in. Hold that thought.

Checks you can run

  • kustomize build app/base | grep -c '^kind:' prints 4: ConfigMap, Secret, Service, Deployment — two written, two generated.
  • Build twice and diff the outputs: no differences. The build is deterministic; if your two runs ever disagree, something outside the folder changed.
  • kustomize build app/base > base.yaml saves the stream. Saving builds to files you can diff is chapter 10's whole method, and it starts here.

The base you just built is what every environment shares. It deliberately says nothing about staging or production — no environment label, a middle-of-the-road replica count, the first release's image tag. Saying those things is the overlays' job, and it is the next chapter.