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. 👋

With 16+ years of open-source contributions, 12+ years of professional hands-on experience in DevOps, and an M.Sc. in Data Engineering from Edinburgh Napier University (UK), I enjoy facilitating the growth of both businesses and individuals.

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

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

2023 Highlights

Image generated with Craiyon . Finally, 2023 is over! What a year! One more crazy year, but it was the culmination ...

Popular Posts

Blog Archive