kubectl error: ValidationError: unknown field \u00a0

created at 07-24-2022 views: 19

error details

Recently, when deploying resources on k8s cluster through kubectl apply -f, I encountered the following error. It was resolved quickly then. The faults and troubleshooting methods are now recorded to facilitate developers who encounter the same error.

> kubectl apply -f nfs.yaml
error: error validating “nfs.yaml”: error validating data: [ValidationError(ServiceAccount): unknown field “\u00a0\u00a0name” in io.k8s.api.core.v1.ServiceAccount, ValidationError(ServiceAccount): unknown field “\u00a0\u00a0namespace” in io.k8s.api.core.v1.ServiceAccount]; if you choose to ignore these errors, turn validation off with --validate=false


The error message has been clearly described, it is caused by the two characters \u00a0\u00a0 before name. According to the query data, \u00a0 in utf-8 encoding means non-breaking space, which is mainly used in Office, so that a word will not be displayed at the end of a new line. In Word, it can be entered via Ctrl+Shift+Space .

We opened the nfs.yaml file in the IDEA editor, and then looked for spaces, and found that name and all whitespace characters indicating indentation were not matched. Also verified the error message.


Open with Sublime Text, it's easier to spot differences:


It turns out that the content of this yaml file was copied directly from a word file, and it accidentally contained some special blank characters \u00a0.


The solution is very simple, just replace \u00a0 with ordinary spaces in the editor, IDEA, Sublime Text are both OK for this job.

created at:07-24-2022
edited at: 07-24-2022: