Kustomize in Kubernetes: Customize Without Templates

Kustomize in Kubernetes: Customize Without Templates

Learn how Kustomize lets you keep one clean set of Kubernetes files and reshape it for every environment using bases, overlays, patches, and generators, without a single template placeholder.

Imagine a restaurant that serves the same pizza in ten cities. The core recipe is identical everywhere, but the Mumbai branch wants extra spice, the Delhi branch wants a thinner crust, and the airport branch needs smaller portions. The head chef has two choices. She can write ten separate recipe books and try to keep them in sync forever, or she can keep one master recipe and hand each branch a short sticky note listing only what is different. Kustomize is the sticky note approach for Kubernetes. This tutorial explains how it works, why teams love it, and where it can bite you if you are careless.

1The Problem Kustomize Solves

Every application needs to run in more than one place, and those places are never exactly alike.

One app, many environments

A real application usually lives in several environments. Developers test on a small development cluster. A staging cluster mimics production for final checks. Production serves real customers. Some companies add more copies for different regions or different customers. In every one of these places the application is the same program, but the settings around it differ.

The development copy might need one replica and a tiny memory limit. Production might need twelve replicas, large limits, and a different database address. Staging might use a different domain name. The container image version might be newer in development than in production. All of these are small differences, yet each one lives inside a Kubernetes manifest file, which is the text file that describes what you want the cluster to run.

The copy and paste trap

The simplest way to handle this is to copy the whole set of files once per environment and edit the copies. It works on day one. By month three, someone fixes a bug in the production copy and forgets the other two. By month six, nobody remembers which differences were intentional and which were accidents. The files drift apart, and every release becomes a nervous comparison exercise.

Simple Analogy

Copying files per environment is like photocopying a school timetable for every class and then crossing out and rewriting lines by hand. When the school changes the lunch break, you must find every photocopy and fix it. A shared master timetable with a small note per class would have saved the trouble.

Where Kustomize fits

Kustomize attacks drift directly. You keep one shared set of plain Kubernetes files, and for each environment you write a small description of the changes. Kustomize combines the two and produces the final files. The shared part is written once, the differences are tiny and easy to read, and nothing is copied.

i
Good to know

The word “Kustomize” is simply “customize” spelled with a K, in the same playful way Kubernetes spells its own name. It is a tool for customizing Kubernetes files, nothing more mysterious than that.

2What Kustomize Is, in Plain Words

Kustomize reads ordinary Kubernetes files, applies your changes, and prints new ordinary Kubernetes files.

A tool that edits files, not a template engine

Many people first meet the idea of reuse through templates. A template is a file with holes in it, such as a placeholder for the number of replicas, which a tool fills in with values at the last moment. Template files are not valid Kubernetes files until they are filled in, which makes them hard to read, hard to check, and hard to open in normal editors.

Kustomize takes a different road. Every file you give it is a complete and valid Kubernetes file that could be applied to a cluster exactly as it is. Kustomize does not fill in holes. Instead it takes those complete files and applies a series of precise edits on top, such as “change the replica count to five” or “add this label to everything”. The output is again complete, valid Kubernetes files.

Simple Analogy

A template is a form with blanks that you fill in with a pen. Kustomize is a finished document plus a tracked changes layer. The original always reads as a proper document, and the changes are shown separately on top.

Where it lives

Kustomize started as its own separate program and was later built into the standard Kubernetes command line tool, kubectl. This means that on most machines where kubectl is installed, you already have Kustomize available without installing anything. A standalone Kustomize program also exists, and it often has newer features than the version embedded inside kubectl.

The shape of the idea

flowchart LR
  A[Plain Kubernetes files] --> C[Kustomize]
  B[Kustomization file with your changes] --> C
  C --> D[Final Kubernetes files]
  D --> E[Applied to the cluster]
        
FIG 1 — Kustomize turns plain files plus a change list into final files

There are three important ideas hiding in this picture. First, the input files stay untouched on disk. Second, the change list is its own small file that names what to modify. Third, the output is generated fresh every time, so there is nothing to keep in sync by hand.

!
Common misconception

Kustomize is not a package manager and it does not install software on its own. It only produces files. A different step, usually the standard apply command, sends those files to the cluster.

3Core Vocabulary You Need

A handful of words cover almost everything in Kustomize.

Term 1

Manifest

A text file describing something you want in the cluster, such as an application deployment, a network service, or a configuration bundle.

Term 2

Kustomization

The special file at the heart of every Kustomize folder. It lists which manifests to include and which changes to apply. It is the sticky note.

Term 3

Base

A folder holding the shared, environment neutral version of an application. It is the master recipe.

Term 4

Overlay

A folder that points at a base and adds environment specific changes on top. Each environment gets its own overlay.

Term 5

Patch

A small description of a change to one existing object, such as raising memory limits on a single deployment.

Term 6

Transformer

A built-in helper that applies a common change across many objects at once, such as adding a label to everything or changing every image version.

Term 7

Generator

A helper that creates new configuration or secret objects from plain files or key and value pairs, so you do not write those objects by hand.

Term 8

Component

A reusable bundle of changes for an optional feature that you can switch on for some overlays and leave off for others.

How the words connect

You write a base, which is a folder of normal manifests and one kustomization file. You then write one overlay per environment, each with its own kustomization file that names the base and lists patches and transformers. When you ask Kustomize to build an overlay, it loads the base first, applies the overlay’s changes, and prints the result.

i
Easy memory trick

Base is what stays the same. Overlay is what is different. Patch and transformer are the two ways to express the difference.

4Bases and Overlays: The Heart of Kustomize

Layering is the single idea that makes everything else fit together.

The layered folder structure

The classic project layout has one folder for the base and a parent folder for the overlays, with one subfolder per environment. Each folder contains its own kustomization file. The base folder also holds the real manifests. The overlay folders usually hold only a kustomization file and a few small patch files.

FolderWhat it containsPurpose
BaseDeployment, service, and other shared manifests plus a kustomization fileThe common definition used by every environment
Overlay for developmentA kustomization file and small patchesOne replica, low limits, test settings
Overlay for stagingA kustomization file and small patchesProduction-like settings with test data
Overlay for productionA kustomization file and small patchesMany replicas, high limits, real addresses and domain names
flowchart TD
  B[Base with shared manifests]
  D[Development overlay]
  S[Staging overlay]
  P[Production overlay]
  B --> D
  B --> S
  B --> P
  D --> DO[Dev output]
  S --> SO[Staging output]
  P --> PO[Production output]
        
FIG 2 — One base feeding several overlays

What an overlay can do

An overlay can add new objects that only exist in that environment, remove or replace parts of existing objects, change names, move everything into a different namespace, attach labels and notes, and choose different container image versions. Because every overlay starts from the same base, a fix made once in the base automatically reaches all environments the next time they are built.

Simple Analogy

Think of tracing paper placed over a printed map. The map underneath is the base. Each sheet of tracing paper adds roads, notes, or colors for one purpose. Stack different sheets and you get a different map, while the original never changes.

Overlays can stack

An overlay may itself serve as the base for another overlay. A company might have a shared overlay for all production clusters, and then region specific overlays that build on it. Layers can nest as deeply as needed, but each added layer makes it harder to understand the final output, so most teams stop at two or three.

!
Keep it shallow

A stack of five overlays means that to understand one deployment setting, a person must open five folders. Prefer wide structures with a few layers over tall structures with many.

5The Kustomization File Explained

Every Kustomize folder is controlled by one small file that acts as its table of contents and its change list.

What goes inside

The kustomization file is itself a Kubernetes style document. It carries an API version and a kind, and then a set of fields that tell Kustomize what to do. Most fields are optional. A tiny kustomization file might do nothing more than list the manifests to include. A large one might hold dozens of instructions.

Field

resources

Lists the manifests, folders, or remote locations to pull in. This is how an overlay points at its base.

Field

namespace

Sets the namespace on every namespaced object, so one build lands entirely in one place.

Field

namePrefix and nameSuffix

Add text to the start or end of every object name, which is handy for keeping environments or tenants apart.

Field

labels and commonAnnotations

Attach the same labels or notes to every object in the build.

Field

images

Changes container image names, version tags, or exact digests everywhere they appear.

Field

replicas

Sets the number of copies for named workloads without writing a patch.

Field

patches

Lists targeted edits to specific objects, either inline or in separate files.

Field

configMapGenerator and secretGenerator

Create configuration and secret objects from files or literal values.

Field

components

Include reusable optional feature bundles.

Field

replacements

Copy a value from one place in the build to another, such as copying a service name into an environment setting.

Field

helmCharts

Pull in rendered output from a Helm chart so it can be customized like any other base. This needs a special flag to be switched on.

Why a small file is a feature

Because the file is short and declarative, a reviewer can read it in under a minute and know exactly what an environment changes. Compare this with reading a fully copied set of fifty files and hunting for differences. Kustomize makes the differences the star of the show.

i
Naming note

Kustomize looks for the file under a few accepted names. Stick to the common one so that every teammate and every tool finds it without extra settings.

6Transformers: Changing Many Things at Once

Transformers are the broad brushes of Kustomize.

Why built-in helpers exist

Some changes apply to nearly every object. Giving every object an environment label, moving all of them into one namespace, or pointing every container at a new image version are all examples. Writing a separate patch for each object would be tedious and error prone. Transformers do these jobs in one line each.

Namespace transformer

Places every object in the named namespace. Kustomize also adjusts references, so objects that point at each other by namespace stay connected.

Name prefix and suffix transformers

Rename every object consistently. Kustomize notices where objects refer to one another by name, such as a deployment pointing at a configuration bundle, and updates those references so nothing breaks.

Label and annotation transformers

Add the same labels or notes to every object. The label transformer can also choose whether to touch the selectors that connect services to pods, which is a very important choice described below.

Image transformer

Finds every container image reference with a matching name and changes its name, its version tag, or pins it to an exact digest. This is the most common tool for releases, because a pipeline only needs to say “use version 2.4.1 now”.

Replica transformer

Sets the replica count for named workloads, so scaling an environment is a one line change.

The selector trap with labels

Kubernetes connects services and workloads through label selectors. A service finds its pods by asking for pods carrying certain labels. A deployment finds the pods it owns the same way. The selector on an existing deployment cannot be changed after it is created. If a transformer blindly adds a new label to the selectors as well as to the objects, applying the result on top of an existing deployment will be rejected by the cluster.

Older Kustomize features called “common labels” always touched selectors, which surprised many teams. The newer labels field lets you decide, label by label, whether selectors and pod templates should receive the label. For labels that are only informational, such as an ownership tag, leave selectors alone.

!
Common mistake

Adding a new label to selectors on a running deployment. The cluster refuses the change because selectors are fixed for the life of the object. Add informational labels without touching selectors.

7Patches: Precise Edits to Single Objects

When a change is specific to one object, a patch is the right tool.

Two flavors of patch

Kustomize supports two styles of patch, and each has its place. Both are listed under the patches field of the kustomization file and both can point at their targets by kind, name, namespace, or even by label.

AspectStrategic merge patchJSON patch
How it readsA partial copy of the object showing only what changesA list of numbered operations such as add, replace, and remove with exact paths
Ease of readingVery easy, it looks like the original fileHarder, you must follow paths step by step
List handlingUnderstands Kubernetes lists and matches items by name, such as containersTargets list items by position, which is fragile
Removing thingsPossible with a special delete directiveDirect with a remove operation
Works on custom resource typesLimited, because it needs to know how lists mergeWorks everywhere
Best forEveryday changes to well known objectsSurgical edits, custom resources, and removals

Strategic merge patches in practice

A strategic merge patch looks like a thin version of the original object. It names the object it wants to change through its kind and name, and then includes only the fields to be altered. Kustomize merges it into the base. When a field already exists, the patch value wins. When a list such as the list of containers is involved, Kustomize matches items by their name, so a patch that names one container changes only that container and leaves the rest alone.

Simple Analogy

A strategic merge patch is like a sticky note placed on a page saying “in the third paragraph, change the number to five”. You do not retype the whole page, you only describe the one change.

JSON patches in practice

A JSON patch is a list of steps. Each step says what to do, where to do it, and, for adds and replacements, what value to use. The location is a path that walks from the top of the object down to the exact spot, much like a postal address from country down to house number. JSON patches shine when you need to remove something, when you edit a custom resource type that strategic merging does not understand, or when you must insert an item at a precise position.

Choosing a target

A patch can aim at exactly one object by name, at all objects of a certain kind, or at any set of objects selected by label or annotation. Broad targeting is powerful but risky, because a patch that quietly matches more objects than expected will alter things you never meant to touch. Prefer precise targets and confirm by reading the output.

i
Practical advice

Start with a strategic merge patch because it is easy to read. Move to a JSON patch only when the situation truly needs it.

8Generators: Configuration and Secrets Without the Boilerplate

Generators create objects for you and fix a subtle problem that has bitten many teams.

The configuration problem

Applications need settings, such as feature switches or database host names. Kubernetes stores these in a configuration object, called a ConfigMap, and passwords and tokens in a Secret object. Writing these objects by hand means wrapping each file or value in a lot of ceremony. Generators let you point at plain files or list simple key and value pairs, and Kustomize builds the full objects.

The hash suffix trick

Here is a classic Kubernetes surprise. You change a setting inside a configuration object and apply it. The object updates, but the running pods that use it are not restarted, so they keep working with old values until something else triggers a restart. Many teams have spent hours wondering why a change did not take effect.

Kustomize solves this elegantly. By default, a generated object gets a short random looking tag at the end of its name, calculated from its content. If the content changes, the tag changes, so the object gets a new name. Kustomize then automatically updates every deployment that refers to it. Because the deployment now points at a different name, its pod definition has changed, and Kubernetes performs a normal rolling update with the new settings. Config changes now behave like code changes.

sequenceDiagram
  participant D as Developer
  participant K as Kustomize
  participant C as Cluster
  D->>K: Change a setting value
  K->>K: Calculate new content tag
  K->>K: Name config object with new tag
  K->>K: Update deployment references
  K->>C: Apply new files
  C->>C: Roll pods to the new config
        
FIG 3 — How a hash suffix turns a config change into a safe rollout
Simple Analogy

Imagine a restaurant whose menu is printed fresh and stamped with a version number every time a dish changes. Waiters always carry the newest version because the old one has a different number and is replaced at the start of the next shift.

When to turn the suffix off

The suffix can be disabled through generator options. This is useful when another system refers to the object by a fixed name, or when you intentionally want changes to be picked up without restarts. Be aware that turning it off brings back the original surprise, so you will need another way to restart workloads when settings change.

Secrets need extra care

A secret generator can read values from files or literals, but the source files still sit in your repository in readable form. Storing real passwords this way defeats the purpose. Production teams combine Kustomize with sealed or external secret tools, so the repository holds only encrypted or reference information, and the real values are delivered to the cluster another way.

!
Security warning

Kubernetes secrets are only encoded, not encrypted, in the files Kustomize prints. Never commit real production passwords into a repository just because a generator can read them.

9Name References and Smart Rewiring

Kustomize does more than text replacement. It understands how Kubernetes objects point at each other.

Objects refer to each other by name

A deployment names the configuration object it mounts. A service account is named by the workloads that use it. An ingress names the service it sends traffic to. A role binding names both a role and a subject. These are all connections made by name, and a simple search and replace would easily miss or damage them.

When a transformer changes a name, adds a prefix, or when a generator adds a hash suffix, Kustomize walks through its built-in knowledge of Kubernetes fields and updates every reference it recognizes. That is why renaming an object in an overlay does not silently break its neighbors.

Where it works well

Standard Kubernetes kinds and their well known reference fields, such as environment variable sources, volume sources, service accounts, and ingress backends, are handled automatically.

Where it needs help

Custom resource types invented by third party tools have fields that Kustomize does not know hold names. For these, a configuration entry can teach Kustomize where such references live, so renames and prefixes still stay consistent.

Replacements for custom wiring

The replacements feature copies a value from one place to another during the build. For example, a service name defined once can be copied into an application setting that needs it, so the two never disagree.

Older Kustomize versions used a variables feature for this kind of copying. It has been deprecated in favor of replacements, which are more explicit about their source and destination and easier to reason about.

i
Design tip

If a value must be the same in two places, define it once and copy it with a replacement instead of typing it twice and hoping nobody edits only one.

10Components: Reusable Optional Features

Sometimes a bundle of changes belongs in some environments but not others, and does not fit neatly into one overlay.

The problem overlays cannot solve alone

Suppose you have an optional feature, such as extra monitoring, a caching layer, or an extra security helper container. Production needs it. Staging needs it. Development does not. A third group of customer specific clusters needs it only for some customers. Writing this feature into several overlays duplicates it, and putting it in the base forces it on everybody.

How components help

A component is a folder with its own kustomization file of a special kind. It contains the files and patches for one feature. Any overlay can include the component in a components list, and the feature is added. Overlays that do not list it are unaffected. One feature, written once, switched on wherever needed.

flowchart LR
  B[Base]
  M[Monitoring component]
  C[Cache component]
  P[Production overlay]
  S[Staging overlay]
  D[Development overlay]
  B --> P
  B --> S
  B --> D
  M --> P
  M --> S
  C --> P
        
FIG 4 — Components switched on only for the overlays that need them
Simple Analogy

Components are like optional add-on packs for a car. The basic car is the base. The sunroof pack, the safety pack, and the sound pack can each be ticked or left unticked for every buyer without redesigning the car.

!
Maturity note

Components use an API version that has been labeled early stage for a long time, even though they are widely used. Check the documentation for the version you run, and pin your Kustomize version in pipelines so behavior does not shift under you.

11How Kustomize Works Inside

Knowing the build pipeline makes surprising results easy to explain.

The build, step by step

1

Load the resources

Kustomize reads every file and folder named in the resources list. If a folder is named, it builds that folder first, recursively, so a base is fully built before its overlay touches it.

2

Run the generators

Configuration and secret objects are created from your files and literals, and the content based names are calculated.

3

Apply patches

Each patch is matched to its targets and merged in. Patches run after the generators, which means patches can edit generated objects too.

4

Run the transformers

Namespaces, prefixes, labels, annotations, images, and replica counts are applied across the whole set, and references between objects are rewired.

5

Run replacements and finishing steps

Value copying and any final adjustments are performed.

6

Sort and print

The finished objects are arranged in a sensible order, with things like namespaces and custom type definitions placed before the objects that depend on them, and printed as plain text.

Nothing is stored

Kustomize keeps no memory between runs. There is no state file, no database, and no record of what it produced before. Every build starts from the files on disk and produces the same output for the same input. This statelessness makes Kustomize easy to reason about and easy to run in any pipeline, but it also means Kustomize alone cannot tell you what to delete from the cluster when you remove something from your files.

i
Why this matters

Because the build is predictable, you can run it on a laptop, in a review pipeline, and in the deployment system and expect identical results. That repeatability is one of its biggest strengths.

12Using Kustomize in Daily Work

The everyday loop is short: preview, compare, apply.

The three habits

1

Build and read

Ask Kustomize to print the final result for an overlay and read it. This is the single best debugging step, because you see exactly what would be sent to the cluster.

2

Diff against the cluster

Use the built-in diff feature of kubectl on the Kustomize output. It shows the exact changes that would happen compared with what is running now, which catches surprises before they ship.

3

Apply

Send the output to the cluster with the standard apply command and its Kustomize option. Kubernetes then makes the cluster match the files.

The same output feeds many tools

Because Kustomize prints plain Kubernetes files, the same output can be piped into validators, policy checkers, scanners, or saved as an artifact for audit. Nothing about Kustomize locks you into one deployment method.

Working with remote bases

A kustomization file can pull in a base from a remote repository address. This is a convenient way to reuse a vendor’s or another team’s manifests and customize them locally without copying. The danger is that an address pointing at a moving branch can change under you. Always pin to a specific tag or commit so that your build is reproducible and a surprise upstream edit cannot reach production.

!
Supply chain warning

A remote base is code you did not write that gets applied to your cluster. Review it, pin it to an exact version, and consider mirroring it into your own repository.

13Kustomize and GitOps

Kustomize fits naturally into workflows where Git is the source of truth.

A perfect match

In a GitOps workflow, a controller inside the cluster continuously compares the cluster with the files in a Git repository and corrects any difference. The two most popular tools for this, Argo CD and Flux, both understand Kustomize directly. You point them at an overlay folder and they run the build for you, then apply the result.

This pairing works well because both Git and Kustomize are declarative and predictable. A change to an overlay is a normal code change with a review, an approval, and a history. Rolling back is as simple as reverting a commit.

flowchart LR
  A[Developer changes overlay] --> B[Pull request review]
  B --> C[Merge to main branch]
  C --> D[GitOps controller sees change]
  D --> E[Controller builds with Kustomize]
  E --> F[Cluster updated to match]
        
FIG 5 — A GitOps loop with Kustomize in the middle

Handling image versions in the pipeline

A common pattern is for the continuous integration system to build a new container image and then update the image tag inside the production overlay’s kustomization file. The commit is automatic, reviewed if desired, and the GitOps controller rolls it out. Every release becomes a one line change in Git with a clear author and time.

Pruning and cleanup

Because Kustomize is stateless, removing an object from your files does not delete it from the cluster by itself. GitOps tools solve this by tracking what they created and deleting what disappears from Git. If you use plain apply commands instead, you need a labeling strategy or a pruning option so that removed objects do not linger.

i
Practical advice

Check the pruning behavior of your delivery tool early. Orphaned objects left behind after a rename are a very common source of confusing duplicates.

14Kustomize Versus Helm

These two tools solve related problems in very different ways, and many teams use both.

Two philosophies

Helm packages an application as a chart, which is a collection of templates and a set of default values. Users install it by supplying their own values, and Helm keeps track of each installation as a release that can be upgraded or rolled back. Kustomize avoids templates entirely and works by layering changes on plain files.

AspectKustomizeHelm
Core ideaLayer changes over plain filesFill templates with values
Input files valid on their ownYes, alwaysNo, templates contain placeholders
Packaging and sharingShare folders or repositoriesVersioned charts in repositories
Release tracking and rollbackNone, relies on Git and the delivery toolBuilt in
Logic such as loops and conditionsNot available by designRich template language
Learning curveGentle for simple needsSteeper, because of the template language
Best forYour own applications across environmentsDistributing software to many different users

Choosing between them

If you own the application and need to vary it across your own environments, Kustomize is often the lighter and clearer choice. If you publish software for many outside users who need many configurable options, Helm’s value system and release management are a stronger fit. If you consume a third party chart and want to adjust it, a very common pattern is to render the chart and then customize the result with Kustomize.

Simple Analogy

Helm is like buying a flat pack furniture kit with a manual and adjustable options. Kustomize is like taking finished furniture and having a carpenter modify it. Each is better in different situations, and some projects use a kit and then ask the carpenter for adjustments.

i
Best of both

Kustomize can inflate a Helm chart when a special flag is turned on, which lets you keep the vendor chart untouched while applying your own patches in a clean, separate layer.

15Advantages and Limitations

An honest look at the trade-offs helps you decide where Kustomize belongs in your toolbox.

Advantages

  • Every input file is plain, valid Kubernetes, so editors, validators, and people can read it normally.
  • Differences between environments are small, explicit, and easy to review.
  • Built into kubectl, so there is nothing extra to install for basic use.
  • Stateless and predictable, which makes builds repeatable in any pipeline.
  • Smart handling of names and references prevents many silent breakages.
  • Hash suffixes turn configuration changes into safe rolling updates.
  • Works naturally with GitOps tools and with any tool that accepts plain files.

Disadvantages / Trade-offs

  • No loops, conditions, or functions, so highly dynamic needs are awkward or impossible.
  • No release tracking, rollback history, or install lifecycle of its own.
  • Patch heavy overlays can become hard to follow, especially with many layers.
  • The version embedded in kubectl can lag behind the standalone tool, causing feature surprises.
  • Stateless design means cleanup of removed objects needs another mechanism.
  • Secrets handling is basic and needs outside tooling for real protection.

When Kustomize is a great fit

Kustomize shines when you have a modest number of applications, a clear difference between environments, and a team that values readable files over clever logic. It is also excellent for adapting third party manifests with a few tweaks.

When to look elsewhere

If your configuration needs heavy computation, such as generating dozens of similar objects from a list, or if you need to distribute a product to outside users with many options, a templating tool or a configuration programming language may serve better. Recognizing this early saves you from forcing Kustomize into a role it was not designed for.

16Security and Safety

Kustomize itself is simple, but what it builds ends up running in your cluster, so safety habits matter.

Protect the source of truth

Your overlay folders decide what runs in production. Anyone who can change them can change your production environment. Protect these folders with the same review rules you apply to application code, including required reviews, protected branches, and clear ownership of production overlays.

Secrets

Keep real secret values out of the repository. Use an external secrets system, a sealed secrets approach, or a cloud secret manager, and let Kustomize handle only the references. Remember that the output of a build may contain secret objects in readable form, so never write build output to shared logs.

Remote content and load restrictions

By default Kustomize refuses to read files from outside the folder tree of the kustomization it is building. This is a protective rule, designed to stop a build from quietly reading unrelated files on the machine. A flag exists to relax this, but turning it off in a shared pipeline weakens a useful safety net. For remote bases, pin to exact versions as discussed earlier.

Plugins and external functions

Kustomize can run external plugins or containerized functions to generate or transform content. These run code during the build, so they need the same trust as any program in your pipeline. They are switched on by explicit flags, which is a deliberate speed bump. Allow only reviewed, pinned plugins in shared systems.

Validate the output

The final files can be checked by schema validators and policy tools before they reach the cluster. A pipeline that builds every overlay, validates the output, and fails on violations catches mistakes in minutes instead of in production.

!
Remember

A tidy overlay structure does not make the result safe. Kustomize happily builds a privileged container or an open network rule if you tell it to. Policy checks on the output are what enforce your standards.

17Verification, Pipelines, and Observability

Since Kustomize is a build step, the way to monitor it is to verify its output at every stage.

Build every overlay on every change

The cheapest safety net is a pipeline job that builds every overlay whenever any file changes. A broken patch, a missing file, or a bad reference shows up immediately as a failed build, long before it reaches a cluster. Building all overlays, not just the one you edited, catches changes to the base that accidentally break a different environment.

Check 1

Build succeeds

Every overlay must build without errors, including overlays nobody touched.

Check 2

Schema validation

Run the output through a validator that knows the Kubernetes object definitions, so typos and wrong field names are caught.

Check 3

Policy checks

Verify rules such as no privileged containers, required labels, and approved image registries on the final output.

Check 4

Diff review

Show reviewers the difference between the old output and the new output, not only the difference in source files. This reveals the true effect of a change.

Observe what the cluster is doing

Once applied, normal cluster monitoring takes over. GitOps controllers report whether the cluster matches Git, how long syncs take, and which objects have drifted. Alerting on sync failures and on drift tells you when someone changed something by hand or when a build produced something the cluster rejected.

Record what was built

Saving the final built files as an artifact for each release gives you an exact record of what was applied and when. This is invaluable during audits and incident reviews, because the source files alone do not show the final merged result.

i
Habit worth building

Treat the rendered output as the real deliverable and the overlay files as its source code. Review, test, and archive the output just as you would a compiled program.

18Real-World Usage Scenarios

These patterns appear again and again in real organizations.

Classic multi-environment delivery

One base per application, with overlays for development, staging, and production. Image versions flow forward by editing each overlay’s image field, and risky settings such as replica counts and resource limits are reviewed per environment.

Multi-region deployments

A company serving customers across continents keeps a shared production overlay and thin regional overlays that set region specific domain names, storage classes, and capacity.

Multi-tenant platforms

A software provider runs one copy of an application per customer. A shared base holds the product, and each customer gets a tiny overlay with its name prefix, namespace, and a few custom settings, which makes onboarding a new customer a matter of adding one small folder.

Adapting third party software

A team downloads vendor manifests as a remote base pinned to a release and adds patches for company needs, such as extra labels, resource limits, and private image locations, without ever editing the vendor files.

Platform baseline components

A platform team publishes components for monitoring agents, logging sidecars, and standard security settings. Application teams opt in by listing the components they want, which spreads good defaults without central enforcement chores.

Preview environments

A pipeline creates a short lived overlay for every pull request, with a unique name prefix and namespace, builds it, applies it, and deletes it when the request closes. Reviewers can test real changes in an isolated copy.

1
Shared base for all environments
Few
Lines of difference per overlay
0
Template placeholders required

19Design Patterns That Work

Teams that keep Kustomize tidy for years follow a few common habits.

Pattern 1

Complete, runnable base

Keep the base valid on its own so anyone can build and read it, and keep environment specifics out of it entirely.

Pattern 2

Thin overlays

Each overlay should contain only real differences. If an overlay grows large, ask whether those settings belong in the base.

Pattern 3

One concern per patch

Small named patches, each doing one thing, are easier to review and remove than one giant patch file.

Pattern 4

Components for optional features

Use components for features that cut across overlays instead of duplicating patches between folders.

Pattern 5

Images as the release lever

Use the image field as the single place where versions are bumped, so a release is one clean line of change.

Pattern 6

Build all overlays in CI

Automatic builds of every overlay catch cross-environment breakage early.

Pattern 7

Pinned tools and sources

Pin the Kustomize version and any remote base versions so builds are reproducible next year as well as today.

Patterns to avoid

ANTI-PATTERN-01 Avoid
Problem

Overlays are stacked five or six layers deep, each adding a little, so nobody can tell where a final value comes from.

Why It’s Harmful

Debugging requires opening many folders, a change in a middle layer ripples unpredictably, and new teammates struggle to learn the structure.

Correct Approach

Keep to two or three layers, use components for shared optional features, and rely on built output to explain results.

ANTI-PATTERN-02 Avoid
Problem

The base quietly contains production specific values, and overlays for other environments patch them back out.

Why It’s Harmful

The base no longer represents a neutral starting point, and every non production overlay carries a long list of undo patches that are easy to forget.

Correct Approach

Keep the base neutral and safe, and add production settings only in the production overlay.

ANTI-PATTERN-03 Avoid
Problem

Patches use broad targets that match every object of a kind, and teams rarely read the built output.

Why It’s Harmful

A new object added later is silently altered by an old patch, producing changes nobody intended and nobody notices until something misbehaves.

Correct Approach

Target patches precisely by name, and review the built output or a diff on every change.

ANTI-PATTERN-04 Avoid
Problem

Real passwords and tokens are stored in plain files read by a secret generator and committed to the repository.

Why It’s Harmful

Anyone with read access to the repository, now and in its entire history, can read production credentials.

Correct Approach

Keep only references or encrypted values in Git and deliver real secrets through a dedicated secrets system.

ANTI-PATTERN-05 Avoid
Problem

A remote base points at a moving branch name rather than a fixed release.

Why It’s Harmful

An upstream change can alter your production build without any change in your own repository, which breaks reproducibility and is a supply chain risk.

Correct Approach

Pin to a specific tag or commit and update it through a deliberate, reviewed change.

20Best Practices and Common Mistakes

A short checklist helps you adopt Kustomize without learning every lesson the hard way.

1

Start with a clean base

Make sure the base builds and applies to a test namespace on its own before writing any overlay.

2

Add overlays one at a time

Begin with development, confirm the output, then add staging and production, and keep each overlay small.

3

Prefer built-in features over patches

Use the images, replicas, namespace, and labels fields wherever they fit, and reserve patches for changes they cannot express.

4

Mind selectors and labels

Never add new labels to selectors of running workloads, and use the labels field with care.

5

Keep the hash suffix unless you have a reason

It gives safe, automatic rollouts when configuration changes.

6

Read the output and diff before apply

Make this a team habit and automate it in review pipelines.

7

Pin versions

Pin the tool version, remote sources, and image versions, so builds are repeatable.

8

Plan cleanup

Decide how removed objects are deleted from clusters before you need it.

!
Frequent mistakes

Patching the wrong object because of a broad target, forgetting that patches apply after generators, expecting variable-like logic that Kustomize deliberately does not offer, committing secrets, and being surprised by a different Kustomize version inside kubectl than on a colleague’s machine.

21Troubleshooting Common Problems

Most Kustomize problems fall into a few recognizable families.

SymptomLikely causeWhat to check
Build fails saying a file was not foundA resource path is wrong or a folder has no kustomization filePaths in the resources list and the presence of the kustomization file in each folder
Build refuses to read a file outside the folderLoad restriction protecting against outside readsRestructure folders so needed files are inside the tree, or reconsider the design
A patch seems to do nothingThe target does not match, or the name was changed by a prefix firstKind, name, and namespace in the target, and the output after transformers
A patch changed too many objectsTarget is too broadNarrow the target by name or use selectors carefully
Apply rejected with a selector errorA label was added to selectors of an existing deploymentLabels field settings, and whether selectors were included
Config change did not restart podsHash suffix disabled or reference not updatedGenerator options and whether the deployment refers to the generated object
Works on one machine, fails on anotherDifferent Kustomize versionsVersion of kubectl’s embedded tool versus the standalone tool, and pin it
Removed object still in the clusterStateless design, nothing was told to delete itPruning settings of the delivery tool or manual cleanup

A calm debugging routine

1

Build the smallest piece

Build the base alone, then add one layer at a time until the problem appears. This pinpoints which layer is responsible.

2

Read the output

Look at the actual produced object, not your intention. The mismatch is usually obvious in the printed text.

3

Compare with the cluster

Use the diff to see what would actually change in the running system.

4

Check the tool version

If behavior differs between machines, confirm that everyone and every pipeline uses the same version.

22Frequently Asked Questions

Q1Do I need to install Kustomize separately?

Not for basic use, because the kubectl command line already contains a version of it. A standalone program also exists and is often newer, so install it if you need recent features.

Q2Does Kustomize change my original files?

No. It reads your files and prints a new result. The originals on disk stay exactly as you wrote them.

Q3Can I use loops or conditions in Kustomize?

No, and that is by design. Kustomize intentionally has no template language. If you need that kind of logic, consider a templating tool or generate the input files before Kustomize runs.

Q4What is the difference between a base and an overlay?

A base is the shared, environment neutral definition. An overlay points at a base and adds the changes that are specific to one environment or purpose.

Q5Should I use a strategic merge patch or a JSON patch?

Start with strategic merge because it looks like the original object and handles Kubernetes lists intelligently. Use a JSON patch for removals, custom resource types, or exact position edits.

Q6Why do my generated configuration objects have strange names?

The short tag at the end is a hash of the content. It makes changes to settings trigger rolling updates automatically. You can disable it through generator options if you have a good reason.

Q7Does Kustomize delete objects I remove from my files?

Not by itself, because it is stateless. Use a delivery tool with pruning support, such as a GitOps controller, or use an explicit cleanup approach.

Q8Can Kustomize and Helm work together?

Yes. Kustomize can inflate a Helm chart when the right flag is enabled, or you can render a chart first and then use its output as a base for further customization.

Q9Is it safe to store secrets with a secret generator?

Not in plain form. The generator reads source files that sit in your repository. Use encrypted or externally managed secrets and keep real values out of Git.

Q10How do I know what my overlay will really produce?

Build it and read the output. Combine that with a diff against the running cluster before you apply anything.

Q11How many overlays and layers are too many?

There is no fixed number, but if understanding one setting means opening more than three folders, the structure is probably too deep. Flatten it or use components.

Q12Does Argo CD or Flux need anything special to use Kustomize?

No. Both recognize a folder containing a kustomization file and build it for you. Point them at the overlay folder for the environment you want to deploy.

23Summary and Key Takeaways

Kustomize offers a calm, readable answer to one of the oldest headaches in Kubernetes, which is running the same application in many slightly different places. By keeping a single shared base and describing each environment as a small overlay, it removes copy and paste drift and makes differences visible and reviewable. Its patches, transformers, generators, and components cover most everyday needs without ever introducing a template language, and its stateless, predictable builds fit neatly into review pipelines and GitOps tools. The price of that simplicity is a lack of logic and lifecycle features, so teams choose it where clear, layered configuration matters more than cleverness. Used with pinned versions, careful targets, secrets kept out of Git, and a habit of reading the output, it becomes a quiet and dependable part of a Kubernetes platform.

Key Takeaways

  • No templates, only layers — every input file is valid Kubernetes, and Kustomize applies changes on top to produce valid output.
  • Base and overlay are the core idea — keep shared definitions in one neutral base and describe each environment as a thin overlay.
  • Use the right tool for each change — built-in transformers for broad changes, patches for single objects, generators for configuration, and components for optional features.
  • Hash suffixes make config changes safe — a changed setting renames the generated object and triggers a rolling update automatically.
  • Mind selectors and targets — never add labels to selectors of running workloads, and aim patches precisely so they do not touch unintended objects.
  • It is stateless — Kustomize builds files and tracks nothing, so plan cleanup, pruning, and secrets handling with other tools.
  • Verify the output, not just the source — build every overlay in CI, validate and diff the result, and pin tool and remote source versions for repeatable builds.