我有一个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
我在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"
]
}
}
}
2条答案
按热度按时间oprakyz71#
服务资源中存在语法错误(
ports
中的数组右括号)。它应该是:要使文件成为有效的JSON文件,可以将定义 Package 在
List
资源中:j7dteeu82#
您可以首先使用
kubectl
应用yaml,然后使用kubectl get deploy,services -o json > example.json
获取jsonJSON的正确语法是在两个资源之间设置
,
,而不是在yaml中使用的---