<p>I am trying to deploy this yaml to create a service for 6 different grok-exporters deployment and I have this error below whenever I try to deploy this manifest:</p>
<pre><code>error converting YAML to JSON: yaml: line 13: did not find expected key and i can't figure out the issue 
</code></pre>
<p>The yaml Manifest:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  name: grok-exporter-centralized-service
spec:
    type: ClusterIP
    ports:
    - name: cluster-autoscaler-grok-exporter-metrics
      protocol: TCP
      targetPort: 9144
      port: 9148
    selector:
      app: cluster-autoscaler-grok-exporter
    - name: evicted-pods-grok-exporter
      protocol: TCP
      targetPort: 9144
      port: 9149
    selector:
      app: evicted-pods-grok-exporter
    - name: flux-hr-grok-exporter
      protocol: TCP
      targetPort: 9144
      port: 9144
    selector:
      app: flux-hr-grok-exporter
    - name: flux-system-grok-exporter
      protocol: TCP
      targetPort: 9144
      port: 9145
    selector:
      app: flux-system-grok-exporter
    - name: ha-proxy-grok-exporter
      protocol: TCP
      targetPort: 9144
      port: 9146
    selector:
      app: ha-proxy-grok-exporter
    - name: spot-requests-grok-exporter
      protocol: TCP
      targetPort: 9144
      port: 9147
    selector:
      app: spot-requests-grok-exporter
</code></pre>
<p>I checked the similar issues here but unfortunately, I couldn't get this script working, so I really appreciate the assistance.</p>
<p>Thanks all!</p>

doksha
<p>Your issue is that you have some <code>spec.selector.app</code> after each <code>spec.ports</code>. There should be only one selector, the ports array should list all ports with no interruption</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: grok-exporter-centralized-service
spec:
    type: ClusterIP
    ports:
    - name: cluster-autoscaler-grok-exporter-metrics
      protocol: TCP
      targetPort: 9144
      port: 9148
    - name: evicted-pods-grok-exporter
      protocol: TCP
      targetPort: 9144
      port: 9149
    - name: flux-hr-grok-exporter
      protocol: TCP
      targetPort: 9144
      port: 9144
    - name: flux-system-grok-exporter
      protocol: TCP
      targetPort: 9144
      port: 9145
    - name: ha-proxy-grok-exporter
      protocol: TCP
      targetPort: 9144
      port: 9146
    - name: spot-requests-grok-exporter
      protocol: TCP
      targetPort: 9144
      port: 9147
    selector:
      app: spot-requests-grok-exporter
</code></pre>
<hr />
<p>Second take: assuming that we want a single service pointing to several exporters, driven by distinct deployments. And that all those exporters would listen on the same port, <code>9144</code>.</p>
<p>In addition to the current labels configured on your deployments, we would add a new one, shared between all those exporters / deployments. Say <code>foo=bar</code>.</p>
<p>Now, I can create a single &quot;exporter&quot; service, whose endpoints would target all my exporter ports:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: generic-exporter
spec:
    type: ClusterIP
    ports:
    - name: generic-exporter
      protocol: TCP
      targetPort: 9144
      port: 9144
    selector:
      foo: bar
</code></pre>
