英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论