Skip to main content
In this tutorial, you’ll learn how to apply common Kustomize transformers—labels, annotations, name prefixes/suffixes, namespaces, and image updates—across your Kubernetes manifests. We’ll use a simple API and database example to demonstrate each feature step by step.

Directory Layout

Our project structure separates API and database manifests into their own folders:
The image shows the Visual Studio Code interface with a project open, displaying a file explorer on the left with YAML files organized under "api" and "db" folders. The main area shows the VS Code logo and some keyboard shortcuts.
Each subdirectory’s kustomization.yaml declares its local resources. For example, api/kustomization.yaml:
And db/kustomization.yaml:
The root kustomization.yaml aggregates both:

1. Global Labels with commonLabels

To tag all resources with department=engineering, add a commonLabels section at the root:
Build the manifests:
Excerpt of the generated YAML shows the label applied everywhere:

2. Scoped Labels in Subdirectories

Labels in a subdirectory only affect its own resources. API folder example (api/kustomization.yaml):
After rebuilding:
  • API resources include both department=engineering and feature=api.
  • DB resources remain only department=engineering.
Similarly, add feature: db to db/kustomization.yaml:

3. Assigning a Namespace

To place all resources into a namespace (e.g., debugging), set namespace at the root:
Rebuild and notice each resource now has:

4. Name Prefixes and Suffixes

Global Prefix

In the root kustomization.yaml:
Every resource name is prefixed with KodeKloud-.

Subdirectory Suffixes

  • api/kustomization.yaml:
  • db/kustomization.yaml:
Resulting resource names:
  • name: KodeKloud-api-deployment-web
  • name: KodeKloud-db-deployment-storage

5. Common Annotations

Add commonAnnotations at the root to include annotations globally:
Each manifest’s metadata now contains:

6. Overriding Container Images

Use the images transformer where needed. In db/kustomization.yaml, override the MongoDB image:
Always quote newTag so that it’s parsed as a string by Kustomize.
After building, the DB Deployment spec shows:
Only the specified image is updated; all other container images remain unchanged.

Kustomize Transformers at a Glance


Next, try these transformers hands-on to see how they simplify your Kubernetes deployments.

Watch Video

Practice Lab