One shared base, plus a small overlay per customer that only records the differences, so upstream fixes only need to be changed once.

FDE 别再为每个客户复制一份 YAML

Image: Raysonho @ Open Grid Scheduler / Grid Engine / CC0

Key takeaways

  • Copying and modifying YAML for each customer makes it hard to merge upstream improvements. Kustomize was created precisely to solve this problem.
  • An overlay is a kustomization that points to a base and patches; a variant is what actually runs in the customer's cluster.
  • Look at rendered output and diffs, not patch files: a wrong patch may be explicitly rejected, or it may silently slip through.

On May 29, 2018, when Google's Jeff Regan and Phil Wittrock introduced kustomize on the Kubernetes blog, they opened with a scenario every Forward Deployed Engineer (FDE) has encountered: copying several YAML files describing API objects and then modifying them to fit your needs.

At that point everything is still fine. The trouble comes later: the original files get improved, but you have no easy way to merge those improvements into your copies.

For an FDE, this repeats with every new customer. Imagine: the first customer needs 3 replicas, the second needs more memory, the third runs in its own namespace. By the fifth customer, the repository contains five nearly identical YAML directories, and no one can tell exactly which lines differ.

Kustomize offers a way out of this loop, without learning a template language. If you are deploying, or about to deploy, the same product to multiple customers, it is worth learning before you write your tenth Helm chart.

What does this tool actually do?

The Kubernetes documentation describes Kustomize as a standalone tool that customizes Kubernetes objects through a kustomization file. It is also built into kubectl: since version 1.14, kubectl can read directories containing a kustomization file. As long as kubectl is that version or newer, you can render and apply overlays without installing anything extra.

The difference lies in the philosophy. The README of the kubernetes-sigs/kustomize project emphasizes that this tool works directly on raw YAML, without templates and without modifying the original files. The 2018 introductory article was titled "Declarative Configuration Customization Without Templates." Your YAML remains valid YAML that anyone can read, with no curly braces mixed in.

Three concepts, matching three things at customer sites

The official glossary defines three concepts that map one-to-one to an FDE's work. The base is the shared part. According to the SIG CLI documentation, an overlay is just another kustomization that points to a base and the patches to apply to it.

A variant is the result in the cluster after the overlay is applied to the base. In FDE terms, a variant is one customer's deployment. The SIG CLI documentation uses a shared base to generate dev, staging, and production variants, and the same mechanism applies just as well to Customer A, Customer B, and Customer C.

Minimal example: two customers, one base

Suppose your product has a Deployment named api. Customer Acme needs 3 replicas, and Customer Beta uses the defaults. The directory structure could look like this:

base/
  deployment.yaml
  kustomization.yaml
overlays/
  acme/
    kustomization.yaml
    replicas.yaml
  beta/
    kustomization.yaml

Acme's overlay only needs to point to the base and declare a patch:

# overlays/acme/kustomization.yaml
resources:
  - ../../base
patches:
  - path: replicas.yaml
# overlays/acme/replicas.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
spec:
  replicas: 3

The entire difference between Acme and the standard product lives in the six lines of this patch file. The Kubernetes documentation also recommends small, single-purpose patches, such as a separate patch for replica counts. When upstream adds a liveness probe to the base, you only change one file, and then

kubectl apply -k overlays/acme

and

kubectl apply -k overlays/beta

will carry the change to both customers.

This is exactly the answer to the problem described in the 2018 introduction: upstream fixes no longer need to be manually copied into every copy.

There is also a side benefit. When a customer asks how their version differs from the standard one, the answer is their overlay directory. When handing over to the customer's operations team, this is also the first thing worth reviewing.

Without templates, what do you lose?

Kustomize's strengths and limitations come from the same choice. Without templates, you cannot write loops or conditionals, such as "if the customer enables feature X, generate three more objects." Every difference must be expressed as a patch against a real base.

As a result, patches are tightly bound to the base's structure. The Kubernetes documentation notes that target resources are matched by group, version, kind, and name in the patch file. Once the base renames a resource, the overlay patching it also misses. So treat the base like an internal API: change it carefully, and re-render every overlay before merging.

If customer configurations vary widely by parameters, a templating tool may be a better fit. But in the most common FDE scenario—the same product with small per-customer differences—the absence of templates is actually an advantage: anyone opening an overlay can immediately see what was changed for that customer.

A wrong patch does not necessarily raise an error

The easiest mistake to make is a typo in a patch while believing the change is done. Whether the error is in the resource name or a field name makes a big difference in the outcome.

When the resource name is wrong—for example, the patch points to

my-app

but no Deployment with that name exists in the base—you will usually see an error immediately. A report on the Kubernetes forum recorded a build aborting with the message "failed to find unique target for patch."

But a community wiki warns that some types of patches are silently skipped when they match no resources, with neither an error nor a warning. This behavior depends on the patch type and the kustomize version.

When a field name is wrong—for example, writing

replicas

instead of

replica

—the API server does not recognize the field, and the outcome depends on validation. kubectl enables strict server-side validation by default, so

kubectl apply

will usually reject unknown fields.

If you disable validation with

--validate=false

, or the cluster is an older version, or the tool you use has its own defaults, the erroneous field may only produce a warning, or be silently dropped. Acme then keeps running with the default replica count, and replicas also remains unchanged in the rendered output or diff.

Look at rendered output, not patch files

The second mistake is applying directly to the customer's cluster before seeing the final YAML. The safeguard is simple: before every apply, especially right after the base has changed, run two commands.

kubectl kustomize overlays/acme
kubectl diff -k overlays/acme

The first prints all resources after the overlay is applied; look in the api Deployment for

replicas: 3

this line. The second compares the cluster's current state with the state after applying. The same community wiki also recommends running this build-plus-diff step for each overlay in CI; in a multi-customer repository, that's exactly what you should do.

When an overlay grows into a second base

The third mistake is harder to spot: a customer's overlay keeps growing until it becomes a second base. At that point you're back to the old problem of copying YAML, just with a renamed directory.

When two overlays carry the same set of patches, that's a sign the patches belong in the base.

What to learn first, and how to present it

First, master base, overlay, and variant, and build the habit of rendering and diffing before applying. Then practice writing patches for fields that commonly differ between customers, such as replicas, resources, and env. When you're on-site with a customer, the first worthwhile task is to find the YAML files that were copied and modified, and consolidate them into a single base.

When interviewing for FDE roles that involve deploying the same product to multiple customers, you can directly ask the team how they manage per-customer configuration. The answer will tell you whether this skill will be useful from day one.

What really carries weight on a resume isn't "familiar with Kustomize" but numbers: how many customers share one base, how many manually copied files were eliminated.

A 20-minute exercise with the Acme example

Rebuild the directory structure above on your machine. Step one: change

replicas.yaml

in

name: api

to

name: apii

, run

kubectl kustomize overlays/acme

, and note whether you get an error or a rendered result with no changes.

Step two: restore the correct name, change

replicas

to

replica

, render again, and look at the api Deployment in the output: which field appears, and

replicas

what is its value. If you have a test cluster, also run

kubectl diff -k overlays/acme

to see how the server handles this unknown field.

Step three: fix the errors and render until you see

replicas: 3

in the output.

These three renders teach you something the patch files themselves will never tell you: whether a patch is correct can only be seen in the output. Only after seeing a customer's changes with your own eyes in the rendered result can you trust an overlay.

Was this article helpful?

Thanks for your feedback!

Next on the roadmap · Phase 5: Deploying to production k9s helps you understand customer clusters faster, but also makes it easier to accidentally delete things. Enable read-only mode before opening production clusters, because ctrl-k deletes resources without asking for confirmation.