【发布时间】:2017-03-19 00:36:30
【问题描述】:
Kubectl 命令总是返回这个错误 yaml: line 2: mapping values are not allowed in this context。即使我调用普通版本命令、配置命令等。不确定是什么原因造成的。
tessact@tessact-sys-1:~$ kubectl version
Client Version: version.Info{Major:"1", Minor:"4",
GitVersion:"v1.4.4",
GitCommit:"3b417cc4ccd1b8f38ff9ec96bb50a81ca0ea9d56",
GitTreeState:"clean", BuildDate:"2016-10-21T02:48:38Z",
GoVersion:"go1.6.3", Compiler:"gc", Platform:"linux/amd64"}
error: yaml: line 2: mapping values are not allowed in this context
tessact@tessact-sys-1:~/[some path]$ kubectl create -f kubernetes_configs/frontend.yaml
error: yaml: line 2: mapping values are not allowed in this context
我使用的唯一yaml文件是
apiVersion: v1
kind: ReplicationController
metadata:
name: frontend
labels:
name: frontend
spec:
replicas: 3
template:
metadata:
labels:
name: frontend
spec:
containers:
- name: trigger
# Replace with your project ID or use `make template`
image: asia.gcr.io/trigger-backend/trigger-backend
# This setting makes nodes pull the docker image every time before
# starting the pod. This is useful when debugging, but should be turned
# off in production.
imagePullPolicy: Always
ports:
- containerPort: 8080
apiVersion: v1
kind: Service
metadata:
name: frontend
labels:
name: frontend
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
name: frontend
无论我用 kubectl 尝试什么,它都会返回此错误。我该怎么做才能解决这个问题?
> tessact@tessact-sys-1:~/developer/trigger-backend-dev/trigger-backend$
> kubectl get service error: yaml: line 2: mapping values are not
> allowed in this context
输出:
strace kubectl version
是here
【问题讨论】:
-
您应该更正您的 YAML。您可能正在使用制表符,删除它们,然后检查缩进是否正确。请将您帖子中的屏幕截图替换为文本(以便对其进行索引)并包含您的 YAML 文件的相关行(从开头到至少第 3 行)。
-
yaml 文件如何影响“kubectl 版本”命令
-
你试过那些网址吗?哪个返回的东西看起来像是损坏的 YAML 文件?损坏文件的具体内容是什么?
-
在我的情况下似乎 yaml 语法错误,使用任何在线 yaml linter 来检查错误。
-
对我来说,原因是我有 'replicas:1' 而不是 'replicas:1',一个空格导致错误,要非常小心和准确地手动编写 yaml
标签: yaml kubernetes kubectl