我正在做一个关于google云中kubernetes的实验室。
我已经创建了YAML文件,但是当我试图部署它时,一个shell显示了这个错误:
error converting YAML to JSON: yaml: line 34: did not find expected keyYAML档案:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
spec:
volumes:
- name: nginx-config
configMap:
name: nginx-config
- name: php-config
configMap:
name: php-config
containers:
- image: php-fpm:7.2
name: php
ports:
- containerPort: 9000
volumeMounts:
- name: persistent-storage
mountPath: /var/www/data
- name: php-config
mountPath: /usr/local/etc/php-fpm.d/www.conf
subPath: www.conf
- image: nginx:latest
name: nginx
- containerPort: 80
volumeMounts:
- name: persistent-storage
mountPath: /var/www/data
- name: nginx-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
volumes:
- name: persistent-storage
persistentVolumeClaim:
claimName: nfs-pvc发布于 2019-02-01 12:54:37
整个文件看起来不错。压痕有一些问题。
YAML文件
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
spec:
volumes:
- name: nginx-config
configMap:
name: nginx-config
- name: php-config
configMap:
name: php-config
containers:
- image: php-fpm:7.2
name: php
ports:
- containerPort: 9000
volumeMounts:
- name: persistent-storage
# looks like indentation issue here
mountPath: /var/www/data
- name: php-config
# looks like indentation issue here
mountPath: /usr/local/etc/php-fpm.d/www.conf
subPath: www.conf
- image: nginx:latest
name: nginx
- containerPort: 80
volumeMounts:
- name: persistent-storage
mountPath: /var/www/data
- name: nginx-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
volumes:
- name: persistent-storage
persistentVolumeClaim:
claimName: nfs-pvc发布于 2019-10-18 22:51:43
yamllint包对于调试和查找此类错误非常有用,只需执行yamllint filename,它就会列出它可能发现的问题。通过发行版包管理器安装(如果可用的话通常推荐安装)或通过下面的npm安装命令(它将在全球范围内安装)
npm install -g yaml-lint
感谢Kyle VG的npm命令
发布于 2020-01-20 12:47:08
在使用Helm为Ingress创建yaml文件时,我得到了这个错误。我有这样的东西作为我的规范
spec:
tls:
- hosts:
- {{ .Values.ingress.host }}在values.yaml中
ingress:
host: "[NAMESPACE]-example.com"结果是导致错误的括号。
这个问题可以通过使用quote函数在值上添加引号来解决。
- {{ .Values.ingress.host | quote }}这也是舵手医生推荐的
避免类型转换错误的最简单方法是对字符串进行显式处理,并对其他所有内容进行隐式处理。或者,简而言之,引用所有的字符串。
和这里
在处理字符串数据时,引用字符串总是比将字符串保留为空话更安全:
https://stackoverflow.com/questions/54479397
复制相似问题