Unmarshalling exception while creating a Service object.

huangapple go评论65阅读模式
英文:

Unmarshalling exception while creating a Service object

问题

以下是我的Service对象

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

在创建此对象时,我收到以下异常,有人知道问题出在哪里吗?

来自服务器的错误(BadRequest):在创建“listing62.yaml”时出错:无法将版本为“v1”的服务处理为服务:json:无法将对象解封为类型为[]v1.ServicePort的Go结构体字段ServiceSpec.spec.ports

英文:

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

得分: 0

尝试检查 ports [] 中是否缺少 -

apiVersion: v1
kind: Service
metadata:
  name: srv1
spec:
  selector:
    name: srv1
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376
英文:

Try you are missing - in ports []

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

答案2

得分: 0

这行是问题:

protocol: TCP

你漏掉了一个连字符。你需要写成:

- protocol: TCP

基本上,如果有一个特定字段的列表(例如容器、端口),通常在开头会有一个连字符。

英文:

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.

huangapple
  • 本文由 发表于 2023年5月29日 20:07:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76357232.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定