<p>I am trying to Json patch an ingress with Kustomize but its failing</p>
<p>ingress patch:</p>
<pre><code>- op: replace
  path: /spec/rules/http/paths/path/backend/serviceName
  value: varnish
- op: replace
  path: /spec/rules/http/paths/path/backend/servicePort
  value: 6091
</code></pre>
<p>Following is my ingress.yaml</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: magento-web
  namespace: magento
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:eu-west-2:AccountID:certificate/aaccxsdssa-bbb-434f-b2f9dss-05xxxx51f30
    alb.ingress.kubernetes.io/listen-ports: '[{&quot;HTTP&quot;: 80}, {&quot;HTTPS&quot;:443}]'
    alb.ingress.kubernetes.io/actions.ssl-redirect: '{&quot;Type&quot;: &quot;redirect&quot;, &quot;RedirectConfig&quot;: {&quot;Protocol&quot;: &quot;HTTPS&quot;, &quot;Port&quot;: &quot;443&quot;, &quot;StatusCode&quot;: &quot;HTTP_301&quot;}}'
    alb.ingress.kubernetes.io/scheme: internet-facing
  labels:
    app: magento-web
spec:
  rules:
    - host: training-example.cloud
    - http:
        paths:
          - path: /*
            backend:
              serviceName: magento-web
              servicePort: 80
</code></pre>
<p>I tried to filter through items from <em><strong>spec</strong></em> but my patch is still failing. I think its something to do here  <em><strong>/spec/rules/http/paths/path/backend/serviceName</strong></em></p>
<p>kustomize.yaml</p>
<pre><code>bases:
  - ../step-3
  - ../bases/varnish

patchesJson6902:
- path: patch/ingress.yaml
  target:
    group: networking.k8s.io
    version: v1beta1
    kind: Ingress
    name: main
    namespace: magento

configMapGenerator:
- name: aux
  namespace: magento
  behavior: merge
  env: config/aux.env
</code></pre>

<p>Rules and paths are JSON-Arrays. So you need the number. I can recommend you a website like <a href="https://jsonpathfinder.com/" rel="nofollow noreferrer">https://jsonpathfinder.com/</a> where you can paste your json and drill down to your fields.</p>
<p>This should work:</p>
<pre><code>- op: replace
  path: /spec/rules/1/http/paths/0/backend/serviceName
  value: varnish
- op: replace
  path: /spec/rules/1/http/paths/0/backend/servicePort
  value: 6091
</code></pre>
