Search code examples
kubernetesservicegoogle-kubernetes-engine

Unmarshalling exception while creating a Service object


Below is my Service object

apiVersion: v1
kind: Service
metadata:
  name: srv1
spec:
  selector:
    name: srv1
  ports:
    protocol: TCP
    port: 80
    targetPort: 9736

When I am creating this object then I get below exception, do anyone knows what is wrong in this?

Error from server (BadRequest): error when creating "listing62.yaml": Service in version "v1" cannot be handled as a Service: json: cannot unmarshal object into Go struct field ServiceSpec.spec.ports of type []v1.ServicePort

I have tried to make changes to the service object but not working.


Solution

  • This line is the problem:

    protocol: TCP

    You are missing a hyphen. You need to put:

    - protocol: TCP

    Basically, if there is a list for a specific field (like, containers, ports), then commonly, there is a hyphen at the start.