尝试在kubernetes中创建POD时出现以下错误。
# kubectl create -f nginx-deployment-prod.yaml
error: error validating "nginx-deployment-prod.yaml": error validating data: found invalid field spec for v1.ObjectMeta; if you choose to ignore these errors, turn validation off with --validate=false
YAML文件如下:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment-prod
spec:
replicas: 1
template:
metadata:
labels:
app: nginx-deployment-prod
spec:
containers:
-
image: "nginx:1.7.9"
name: nginx-deployment-prod
ports:
-
containerPort: 80
检查YAML,如果它有效或不使用http://www.yamllint.com/;请让我知道如何解决这个问题。
答案 0 :(得分:1)
格式化yaml文件时遇到问题:spec
应与metadata
处于同一级别。
正确nginx-deployment-prod.yaml
是:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-deployment-prod
spec:
replicas: 1
template:
metadata:
labels:
app: nginx-deployment-prod
spec:
containers:
- name: nginx-deployment-prod
image: "nginx:1.7.9"
ports:
- containerPort: 80