Im getting the error got "map", expected "string" on kubernetes service yaml

10/13/2020

I´m getting the error

got "map", expected "string",

when I try to apply a service.yaml via..

kubectl apply -f service.yaml

Here is my service.yaml

<!-- begin snippet: js hide: false console: true babel: false --><!-- language: lang-html -->
apiVersion: v1
kind: Service
metadata:
  name: gettime
  labels:
    app: jexxa
spec:
  selector:
    matchLabels:
      app: jexxa
    type: LoadBalancer
    ports:
    - port: 7000
      targetPort: 7000
<!-- end snippet -->

and here the whole error message :

error: error validating "service.yaml": error validating data: >io.k8s.api.core.v1.ServiceSpec.selector: got "map", expected "string", >ValidationError(Service.spec.selector.ports): invalid type for >io.k8s.api.core.v1.ServiceSpec.selector: got "array", expected "string"]; if you choose to ignore >these errors, turn validation off with --validate=false

I also tried it with --validate=false but it didnt work..

-- Nico
kubernetes
yaml

1 Answer

10/13/2020

Below should work. Removed matchLabels

apiVersion: v1
kind: Service
metadata:
  name: gettime
  labels:
    app: jexxa
spec:
  selector:
    app: jexxa
  type: LoadBalancer
  ports:
    - port: 7000
      targetPort: 7000
-- Arghya Sadhu
Source: StackOverflow