<p>I am doing some practices. one of the test cases i tried to override the values of port value. while doing that getting an error as <strong>replace operation does not apply: doc is missing key: /spec/ports/port: missing value.</strong></p>
<pre><code>patches:
  - target:
      kind: Service
      name: cdq-ui-service
    patch: |
      - op: replace
        path: /spec/ports/0/port
        value: 8080
</code></pre>
<p>while applying kustomization in Kubernetes with the patch. that path will be override the port value.</p>

Vijay
<p>You are trying to modify <code>/spec/ports/port</code>, but there is no such path in a Kubernetes service. Recall that a service looks like this:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app.kubernetes.io/name: MyApp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376
</code></pre>
<p>The path <code>/spec/ports</code> is a <strong>list</strong>, not a <strong>dictionary</strong>. You could patch <code>/spec/ports/0/port</code>:</p>
<pre><code>apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- service.yaml

patches:
  - target:
      kind: Service
      name: my-service
    patch: |
      - op: replace
        path: /spec/ports/0/port
        value: 8080
</code></pre>
<p>Which would result in:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  ports:
  - port: 8080
    protocol: TCP
    targetPort: 9376
  selector:
    app.kubernetes.io/name: MyApp
</code></pre>
