Sharing patches between kustomize overlays - does not recognise transformers

3/29/2020

I'm trying to share JSON patches between overlays. I could do something like:

bases:
- ../bases
patchesJson6902:
- target:
  ...

But I'd have to copy the full target for each overlay. I'd prefer to describe the target and patch in one place, then pull that into the overlays that need it.

I therefore tried using this approach where your kustomization.yaml has a transformers directive, pointing at a file explicitly triggering the plugin.

From the docs it looks like this should work in my overlay's kustomization.yaml:

bases:
- ../bases

transformers:
- ../transformers/example

but when I run kubectl apply -k I get:

Error: json: unknown field "transformers"

Can anyone point me at what I'm doing wrong? Is there a better way to do this?

-- Sausage O' Doom
kubernetes
kustomize

2 Answers

3/30/2020

The built-in version of Kustomize is quite old, 2.0.3. This is well before the transformers system was added. You'll have to use an independent version of Kustomize.

-- coderanger
Source: StackOverflow

3/30/2020

You need to install the kustomize binary rather than using kubectl to generate these manifests. As @coderanger mentioned, the version of Kustomize that is bundled with kubectl is from a release that predated Transformers.

After you have installed kustomize, you can then build your manifests like so:

kustomize build >dir<

Then will produce a stream of STDOUT similar to kubectl kustomize >dir<

If you wish to directly apply the resultant manifests to your API server instead, you can pipe STDOUT directly into kubectl apply. For example:

kustomize build >dir< | kubectl apply -f-

-- TJ Zimmerman
Source: StackOverflow