others-How to solve 'SchemaError: invalid object doesn't have additional properties' problem in kubernetes

1. The purpose of this post

Sometimes, when you operate on a resource with kubectl in kubernetes, you would get this error.

error: SchemaError(io.k8s.api.core.v1.ServiceSpec): invalid object doesn't have additional properties

2. Environments

  • docker 19
  • kubernetes 1.17

3. The solution

This is caused by the version of your kubectl, check your kubectl’s version like this:

➜  k8s git:(master) kubectl version  

Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:38:32Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"darwin/amd64"}

Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:12:17Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}

You can see that the version of the client is 1.10,but the server’s version is 1.17, so the solution is upgrade the kubectl client version like this:

If you are using mac:

brew install kubernetes-cli

If you are using linux:

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl

chmod +x ./kubectl

sudo mv ./kubectl /usr/local/bin/kubectl

Now everything works fine.