04/04/2022

Apply Kustomize builtin transformers on a single resource - Kubernetes

Kustomize is a template-free declarative management tool for Kubernetes resources. Kustomize has 2 main concepts: Generators and Transformers. In short, the first able to create K8s manifests, and the second is able to manipulate K8s manifests. In this post, I'm interested in the Kustomize Transformers.

In Kustomize, "everything is a transformer"! In fact, the transformers have a general generative power too! But always remember that transformers run after generators. Anyway, this is not the topic of this post. I just wanted to highlight how powerful Kustomize transformers are.

---

Kustomize has a bunch of default/builtin transformers like namePrefix, nameSuffix, commonAnnotations, and commonLabels (you probably used one of them if you just used Kustomize before). Those builtin transformers are global by default which means they are applied to all resources managed by Kustomize.

The question is, what if you want to apply a change like namePrefix to a specific resource?

You can apply any of Kustomize builtin transformers to certain resources. Here is an example:

# kustomization.yaml
transformers:
- |-
  apiVersion: builtin
  kind: PrefixSuffixTransformer
  metadata:
    name: my-service
  prefix: dev-
  fieldSpecs:
  - path: metadata/name

It works exactly like namePrefix but on a single resource called my-service which will be transformed to dev-my-service.

That's it! :-)

Powered by Blogger.

Hello, my name is Ahmed AbouZaid, I'm a passionate Tech Lead DevOps Engineer. 👋

I specialize in Cloud-Native and Kubernetes. I'm also a Free/Open source geek and book author. My favorite topics are DevOps transformation, DevSecOps, automation, data, and metrics.

More about me ➡️

Contact Me

Name

Email *

Message *

Start Your DevOps Engineer Journey!

Start Your DevOps Engineer Journey!
Start your DevOps career for free the Agile way in 2024 with the Dynamic DevOps Roadmap ⭐

Latest Post

Bootstrap Cloud-Native bootstrappers like Crossplane with K3d - Automation

I created a logo for the Crossplane Bootstrapper because all good projects deserve a logo. 😁 TL;DR ...

Popular Posts

Blog Archive