Skip to main content
In this lesson, you’ll learn how to efficiently modify and manage your Kubernetes manifests using Kustomize. Kustomize streamlines the process of updating common configurations across multiple YAML files by leveraging built-in transformers. This article focuses on a subgroup known as Common Transformers, which help you apply consistent changes such as labels, namespaces, prefixes/suffixes, and annotations without manually updating each resource. Consider an example where you have a basic Deployment and Service defined in separate YAML files:
Suppose you want to add a common configuration—such as a label identifying your organization—to all your Kubernetes resources. Manually editing each YAML file is not scalable, particularly in environments with dozens of resources. Instead, Kustomize applies these common changes automatically using transformers. For example, to add the label “org: KodeKloud” to every resource, you might update your files as follows:
Or, if you need to append a suffix (e.g., “-dev”) to resource names, your Deployment could be modified like this:
Rather than editing each file manually, Kustomize uses transformers to automate these updates. Below are several common transformers you can leverage:

Common Label Transformation

The common label transformer automatically adds a specified label to every resource included in your kustomization.yaml file. For instance, to ensure every resource includes the label “org: KodeKloud”, add the following to your configuration:
When applied, this transformer injects the label into the metadata of every resource, streamlining updates and reducing human error.

Namespace Transformation

Assigning resources to a specific namespace is simplified with the namespace transformer. By specifying the namespace in your kustomization.yaml, you ensure that all resources are deployed into that namespace. For example, consider the following Service definition:
And in your configuration file, include:
This setting ensures that the Service, along with all other defined resources, will be deployed to the “lab” namespace.

Prefix and Suffix Transformation

With the prefix/suffix transformer, you can automatically alter the names of your resources without manually editing every file. For example, to add the prefix “KodeKLOUD-” and suffix “-dev” to a Service name, use the following configuration:
After transformation, the Service’s name will be updated to “KodeKLOUD-api-service-dev”. Here’s an example of the transformed Service resource:

Common Annotations Transformation

If you need to add common annotations to all Kubernetes objects, you can define these in your kustomization.yaml file. For example, to add the annotation “branch: master” everywhere, your configuration might look like this:
This setup guarantees that the annotation is consistently applied across all resources, eliminating the need for repetitive edits.

Summary of Common Transformers

Below is a table summarizing the common transformers available in Kustomize and their use cases: Using these transformers can greatly simplify deployment and maintenance processes, especially when managing a large suite of Kubernetes manifests. For more details on Kubernetes and managing configurations, check out the following resources:

Watch Video