使用yml文件创建deployment类型的pod时,执行命令报错如下:
error: error parsing deployment-nginx.yml: error converting YAML to JSON: yaml: line 19: did not find expected key
yml文件如下:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: test
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
报错说19行有问题
应该是缩进的问题,于是修改了最后几行的缩进
再次创建
修改后的yml文件文章来源:https://www.toymoban.com/news/detail-694542.html
1 apiVersion: apps/v1
2 kind: Deployment
3 metadata:
4 name: nginx-deployment
5 namespace: test
6 labels:
7 app: nginx
8 spec:
9 replicas: 3
10 selector:
11 matchLabels:
12 app: nginx
13 template:
14 metadata:
15 labels:
16 app: nginx
17 spec:
18 containers:
19 - name: nginx
20 image: nginx
21 ports:
22 - containerPort: 80
总结:
属于yml文件格式问题,k8s对于yml/yaml文件格式要求严格,缩进字符数一定要仔细。文章来源地址https://www.toymoban.com/news/detail-694542.html
到了这里,关于error parsing deployment-nginx.yml: error converting YAML to JSON: yaml: line 19 问题解决的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!