kubernetes: error: yaml: line 2: mapping values are not allowed in this context
Is this a request for help? (If yes, you should use our troubleshooting guide and community support channels, see http://kubernetes.io/docs/troubleshooting/.): yes
What keywords did you search in Kubernetes issues before filing this one? (If you have found any duplicates, you should instead reply there.):
kubectl yaml mapping values are not allowed in this context
Is this a BUG REPORT or FEATURE REQUEST? (choose one):
Kubernetes version (use kubectl version
):
v1.2
Environment:
- Cloud provider or hardware configuration:
- OS (e.g. from /etc/os-release): CentOS 7
- Kernel (e.g.
uname -a
): 3.10 - Install tools: yum install
- Others:
What happened: When I execute kubectl create -f X.yaml or kubectl get nodes, I get “error: yaml: line 2: mapping values are not allowed in this context”. This is a serious problem. I cannot use kubernetes to manage my cluster.
What you expected to happen: Who can help me to repair this problem.
How to reproduce it (as minimally and precisely as possible):
Anything else do we need to know:
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 33
- Comments: 32 (9 by maintainers)
Commits related to this issue
- Cambiando a versión v1.2 [Error](https://github.com/kubernetes/kubernetes/issues/30961) — committed to optimizacion-2-2021-1-gh-classroom/practica-2-primera-parte-diramtz by AnaTorresR 3 years ago
When I gave kubectl a malformed YAML I received this error. I would argue the bug here is to make the error message more clear when using multiple YAMLs in the same file. The line number above refers to the start of the current section (‘—’ delimited YAMLs) which is quite confusing if you have many configs in the same file.
Example (purposely malformed Deployment):
Output:
Note: The error is actually on line 19 in the total file. Line 9 is the offset from
---
.I got this error for improper tabbing:
Wrong:
Correct:
The error message isn’t very useful, though, and it would be nice to see some improvement in that respect.
This error for me was caused by use of an em-dash instead of a dash from a downloaded yml sample.
For anyone else that find this, it’s not just invalid YAML. I accidentally forgot “hostPath” in one line and it also fed me this error and it cited the incorrect line. I would interpret this error as, “There is something generically wrong somewhere of the vicinity where we are telling you.”
Can someone help me with this? I get the error of “error converting YAML to JSON: yaml: line 5: mapping values are not allowed in this context”
2 ---- 3 apiVersion:v1 4 kind:PersistentVolume 5 metadata: 6 name: pv-1 7 labels: 8 type: local 9 spec: 10 capacity: 11 storage: 5Gi 12 accessModes: 13 -ReadWriteOnce 14 hostPath: 15 path: /tmp/data/pv-1 16 storageClassName: slow 17 18 — 19 20 apiVersion:v1 21 kind:PersistentVolume 22 metadata: 23 name: pv-2 24 labels: 25 type: local 26 spec: 27 capacity: 28 storage: 5Gi 29 accessModes: 30 -ReadWriteOnce 31 hostPath: 32 path: /tmp/data/pv-2 33 storageClassName: slow
/sig cli /sig api-machinery do we have enough info to provider smarter error messages in this context?
For me, it’s because of an unset environment variable which caused empty string for docker image tag. When validating yml against an online tool, it complained about no value after the colon.
Those who find themselves with this I hit same error due to a rouge colon. Basically you busted your config and system can’t tell what is actually wrong.