本文介绍了将 YAML 转换为 JSON 时出错,未找到预期的密钥 kubernetes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做一个关于谷歌云中 kubernetes 的实验室.
我已经创建了 YAML 文件,但是当我尝试部署它时,shell 向我显示此错误:
I am doing a lab about kubernetes in google cloud.
I have create the YAML file, but when I am trying to deploy it a shell shows me this error:
error converting YAML to JSON: yaml: line 34: did not find expected key
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
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
推荐答案
整体文件看起来不错.缩进有一些问题.
The overall file looks good.There are some issues with indentation.
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
这篇关于将 YAML 转换为 JSON 时出错,未找到预期的密钥 kubernetes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!