Kubectl always returns a error: yaml: mapping values are not allowed in this context Kubectl always returns a error: yaml: mapping values are not allowed in this context kubernetes kubernetes

Kubectl always returns a error: yaml: mapping values are not allowed in this context


That the version command already throws an error indicates that there is some default YAML file that gets loaded.

You can use strace kubectl version to see what file was opened, hopefully this is done just before kubectl throws the error. I assume there is some global config that it reads (or alternatively a default file in your current directory).

It is of course sloppy programming in kubernetes not to catch such an error, and display the name of the file, and then re-raise the error.


Most of the time when you get an error like this (speaking in general and meaningful terms) it is either because of :-

1). A syntax error (in your case it is not) in the yaml file.

2). Or like the error says "mapping values are not allowed in this context". It means that the keys/values you have used in the yaml, may be syntactically right but not semantically.


Make sure you have completed the step:

mkdir -p $HOME/.kube  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/config

Even as root user.

I also wasn't able to see version from

kubectl version