title: Is there a way in "kubectl patch" to delete a specific object in an array without specifying the index?
body: <p>When I use &quot;kubectl patch&quot; to delete a specific object in an array, I need to first check the index of that specific object, and then do the kubectl patch with the json/yaml path.</p>
  <p>For example, I have an resource contains multiple port object:</p>
  <pre><code>spec:
    clusterIP: 100.12.143.76
    externalTrafficPolicy: Cluster
    ports:
    - name: object1
      nodePort: 30681
      port: 1234
      protocol: TCP
      targetPort: 1234
    - name: object2
      nodePort: 31805
      port: 9876
      protocol: TCP
      targetPort: 9876
  </code></pre>
  <p>If I need to remove the &quot;object1&quot; in the ports, here is the command I am using now (kong-proxy is the name of this service resource):</p>
  <pre><code>kubectl patch service kong-proxy --type=json -p='[{&quot;op&quot;: &quot;remove&quot;, &quot;path&quot;: &quot;/spec/ports/0&quot;}]' -n kong
  </code></pre>
  <p>By doing the command above, it deletes the object at index &quot;0&quot; which with the name &quot;object1&quot;.</p>
  <p>But this requires the person to know the correct index number in advance, and if there are too many objects in an array, it will be hard to manage and calculate the index.</p>
  <p>Therefore I wonder without writing a separate bash script, is there a way that I can delete the object with an identifier in it.</p>
  <p>Such as:</p>
  <pre><code>kubectl patch service kong-proxy --type=json -p='[{&quot;op&quot;: &quot;remove&quot;, &quot;path&quot;: &quot;/spec/ports/{name:object1}&quot;}]' -n kong
  </code></pre>