Coo*_*eze 1 json yaml kubernetes
我有一个 YAML 文件,其中包含多个资源部署和服务。
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: petclinic
name: petclinic
spec:
replicas: 1
selector:
matchLabels:
app: petclinic
strategy: {}
template:
metadata:
labels:
app: petclinic
spec:
containers:
- image: arey/springboot-petclinic
name: springboot-petclinic
resources: {}
ports:
- containerPort: 8080
status: {}
---
apiVersion: v1
kind: Service
metadata:
name: petclinic
spec:
type: LoadBalancer
selector:
app: petclinic
ports:
- port: 8080
targetPort: 8080
protocol: TCP
name: http
Run Code Online (Sandbox Code Playgroud)
我正在用 JSON 创建一个类似的文件。我能够使用 JSON 创建部署资源并成功部署,但是当我尝试包含服务资源时,它失败了。任何有关我出错的地方的帮助将不胜感激。下面是 JSON 的片段。
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"creationTimestamp": null,
"labels": {
"app": "petclinic"
},
"name": "petclinic"
},
"spec": {
"replicas": 2,
"selector": {
"matchLabels": {
"app": "petclinic"
}
},
"strategy": {},
"template": {
"metadata": {
"labels": {
"app": "petclinic"
}
},
"spec": {
"containers": [
{
"image": "arey/springboot-petclinic",
"name": "springboot-petclinic",
"resources": {},
"ports": [
{
"containerPort": 8080
}
]
}
]
}
}
},
"status": {}
}
{
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "petclinic"
},
"spec": {
"type": "LoadBalancer",
"selector": {
"app": "petclinic"
},
"ports": [
{
"port": 8080,
"targetPort": 8080,
"protocol": "TCP",
"name": "http"
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
您的服务资源中存在语法错误( 中的数组右括号ports
)。它应该是:
{
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "petclinic"
},
"spec": {
"type": "LoadBalancer",
"selector": {
"app": "petclinic"
},
"ports": [
{
"port": 8080,
"targetPort": 8080,
"protocol": "TCP",
"name": "http"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
要使文件成为有效的 JSON 文件,您可以将定义包装在List
资源中:
{
"apiVersion": "v1",
"kind": "List",
"items": [
{
"apiVersion": "v1",
"kind": "Deployment",
...
},
{
"apiVersion": "v1",
"kind": "Service",
...
}
]
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1207 次 |
最近记录: |