代码之家  ›  专栏  ›  技术社区  ›  Learn and Share

创建服务对象时出现解组异常

  •  1
  • Learn and Share  · 技术社区  · 2 年前

    下面是我的服务对象

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

    当我创建这个对象时,我会出现以下异常,有人知道这里面出了什么问题吗?

    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

    我尝试过对服务对象进行更改,但没有成功。

    2 回复  |  直到 2 年前
        1
  •  0
  •   hagrawal7777    2 年前

    这一行就是问题所在:

    protocol: TCP

    您缺少一个连字符。您需要放置:

    - protocol: TCP

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

        2
  •  0
  •   Harsh Manvar    2 年前

    试试你失踪了 - 在里面 ports []

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