05/05/2021

Delete a manifest from Kustomize base - Kubernetes

Kustomize is a template-free declarative management tool for Kubernetes resources. One of the important primitives of Kustomize is patchesStrategicMerge. It allows you to customize the base manifests according to your needs.

For example, if you have multi env (e.g. dev, stage, and prod), it could be used to set different values for each env. It's also useful to customize off-the-shelf Helm charts.

One of the use cases is when you need to delete a manifest, not just patch (manipulate) it. Hence, Kustomize via Strategic Merge Patch provides some patch options like replace, merge, and delete.

Here are interested in the delete option. Let's assume you have a base, and in of the overlays you want to don't apply a certain manifest for one reason or another; you can do that as following

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - ../base

[...]

patchesStrategicMerge:
- |-
  apiVersion: v1
  kind: Namespace
  metadata:
    name: unwanted-namespace
  $patch: delete

That's it, the namespace that's called unwanted-namespace will not be applied when this Kustomization file is applied.

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