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 and this is my "lite" technical blog!

I'm a passionate DevOps engineer, Cloud/Kubernetes specialist, Free/Open source geek, and an author.

I believe in self CI/CD (Continuous Improvements/Development), also that "the whole is greater than the sum of its parts".

DevOps transformation, automation, data, and metrics are my preferred areas. And I like to help both businesses and people to grow.

Latest Post

🔀Merger🔀, a schemaless strategic merge plugin - Kustomize

Kustomize is a great tool. I've been using Kustomize for almost 4 years and am happy with it. However, it's ...

Popular Posts