Escaping Forward Slash in Kustomize Patches

Kustomize patches escape forward slash ~1 notation annotation path

2 min read | by Jordi Prats

While writing Kustomize patches you might come across is the need to escape certain characters, such as the forward slash (/). This can be a bit tricky since the common conventions on how to escape a character don't apply here.

In Kustomize, the forward slash character is used to separate different parts of a resource's path. But if you have an annotation that contain a forward slash you'll need to escape it otherwise looks like is referencing a different path within the object.

To escape escape a forward slash in Kustomize is to use the ~1 instead of the forward slash, for example:

kind: Kustomization
- deployment.yaml
- op: remove
  path: /metadata/annotations/

Notice how we are using the ~1 notation to escape the forward slash in the annotation name: We are pointing to in the path .metadata.annotations

Posted on 03/05/2023