Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.


1 Answers

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.

like image 145
hagrawal Avatar answered Jan 19 '26 11:01

hagrawal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!