<p>In the Base Ingress file I have added the following annotation <code>nginx.ingress.kubernetes.io/auth-snippet</code> and it needs to be removed in one of the environment.</p>
<p>Base Ingress:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
  annotations:
     nginx.ingress.kubernetes.io/auth-snippet: test
</code></pre>
<p>I created a ingress-patch.yml in overlays and added the below</p>
<pre><code>- op: remove
  path: /metadata/annotations/nginx.ingress.kubernetes.io/auth-snippet
</code></pre>
<p>But it gives the below error when executing Kustomize Build</p>
<pre><code>Error: remove operation does not apply: doc is missing path: &quot;/metadata/annotations/nginx.ingress.kubernetes.io/auth-snippet&quot;: missing value
</code></pre>

Container-Man
<p>The path <code>/metadata/annotations/nginx.ingress.kubernetes.io/auth-snippet</code> doesn't work because <code>/</code> is the character that JSONPath uses to separate elements in the document; there's no way for a JSONPath parser to know that the <code>/</code> in <code>nginx.ingress.kubernetes.io/auth-snippet</code> means something different from the <code>/</code> in <code>/metadata/annotations</code>.</p>
<p>The <a href="https://www.rfc-editor.org/rfc/rfc6901" rel="nofollow noreferrer">JSON Pointer RFC</a> (which is the syntax used to specify the <code>path</code> component of a patch) tells us that we need to escape <code>/</code> characters using <code>~1</code>. If we have the following in <code>ingress.yaml</code>:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
  annotations:
    example-annotation: foo
    nginx.ingress.kubernetes.io/auth-snippet: test
</code></pre>
<p>And write our <code>kustomization.yaml</code> like this:</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ingress.yaml

patches:
  - target:
      kind: Ingress
      name: ingress
    patch: |
      - op: remove
        path: /metadata/annotations/nginx.ingress.kubernetes.io~1auth-snippet
</code></pre>
<p>Then the output of <code>kustomize build</code> is:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    example-annotation: foo
  name: ingress
</code></pre>
