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:
error converting YAML to JSON: yaml: line 13: did not find expected key and i can't figure out the issue
The yaml Manifest:
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
I checked the similar issues here but unfortunately, I couldn't get this script working, so I really appreciate the assistance.
Thanks all!
Your issue is that you have some spec.selector.app
after each spec.ports
. There should be only one selector, the ports array should list all ports with no interruption
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
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, 9144
.
In addition to the current labels configured on your deployments, we would add a new one, shared between all those exporters / deployments. Say foo=bar
.
Now, I can create a single "exporter" service, whose endpoints would target all my exporter ports:
apiVersion: v1
kind: Service
metadata:
name: generic-exporter
spec:
type: ClusterIP
ports:
- name: generic-exporter
protocol: TCP
targetPort: 9144
port: 9144
selector:
foo: bar