canonical / microk8s

MicroK8s is a small, fast, single-package Kubernetes for datacenters and the edge.
https://microk8s.io
Apache License 2.0
8.5k stars 772 forks source link

Error when running the ‘apply’ command on remote kubernetes: error: SchemaError(io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta): invalid object doesn't have additional properties #407

Closed KlausTrikk closed 5 years ago

KlausTrikk commented 5 years ago

Environment:

I have two machines. The first one with clean ubuntu (I have only docker and harbor installed on it). The second - with windows 10 running docker for windows with enabled kubernetes.

I want to connect kubernetes from my windows machine to kubernetes on ubuntu.

I ran a next command to install microk8s on ubuntu: $ sudo snap install microk8s --classic

After that, I got configuration using the command $ microk8s.config

My configuration:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: ***
    server: https://192.168.10.54:16443
  name: microk8s-cluster
contexts:
- context:
    cluster: microk8s-cluster
    user: admin
  name: microk8s
current-context: microk8s
kind: Config
preferences: {}
users:
- name: admin
  user:
    username: admin
    password: ***

I replaced the whole kubernetes configuration file on windows machine with the above configuration text.

Kubernetes version (use ‘kubectl version’ on windows machine) :

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:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.0", GitCommit:"641856db18352033a0d96dbc99153fa3b27298e5", GitTreeState:"clean", BuildDate:"2019-03-25T15:45:25Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}

What happened:

On windows machine, I can successfully run ‘get pods’ command that shows running pods on ubuntu. I even can run ‘delete’ command on windows machine to remove deployment on ubuntu. But when I try to run ‘apply’ command, I got the error

kubectl apply -f https://k8s.io/examples/application/deployment.yaml
error: SchemaError(io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta): invalid object doesn't have additional properties

When I run this command directly on ubuntu, it succeeded.

What you expected to happen:

After executing the command kubectl apply -f https://k8s.io/examples/application/deployment.yaml I expected that I would have running pod on my ubuntu

inspection-report-20190403_082007.tar.gz

ktsakalozos commented 5 years ago

Hi @KlausTrikk, have you tried with a client that matches the 1.14 version?

KlausTrikk commented 5 years ago

No, I only tried to connect from the windows machine that running the latest Docker Desktop for windows v2.0.0.3 with Kubernetes v1.10.11 In my configuration, I need to deploy my application from the windows machine on ubuntu.

KlausTrikk commented 5 years ago

I tried to connect from another ubuntu with microk8s - it works well.

$ microk8s.kubectl version
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.0", GitCommit:"641856db18352033a0d96dbc99153fa3b27298e5", GitTreeState:"clean", BuildDate:"2019-03-25T15:53:57Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.0", GitCommit:"641856db18352033a0d96dbc99153fa3b27298e5", GitTreeState:"clean", BuildDate:"2019-03-25T15:45:25Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}

But I need to connect from windows machine, as I mentioned before. I have no idea what I shroud do.

ktsakalozos commented 5 years ago

@KlausTrikk if you do not want to dig into the API compatibility issues you could try to downgrade MicroK8s. For example to get the 1.12 kubernetes you can:

sudo snap install microk8s --classic --channel=1.12/stable
vinothrao commented 5 years ago

This has happened to me because of wrong version of kubectl installed by docker in the path "C:\Program Files\Docker\Docker\resources\bin" .

I resolved this by following below steps

Install kubectl manually by :

Install-Script -Name install-kubectl -Scope CurrentUser -Force install-kubectl.ps1 [-DownloadLocation ]

(https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-windows)

CD to the [-DownloadLocation ] folder and run kubectl from here . If the location is not given it will install it in temp by default. I have installed it in temp PS C:\Users\sysadmin\AppData\Local\Temp> : .\kubectl.exe version

If the version mismatch run the command again and check. Try kubectl apply from this location.

PS C:\Users\sysadmin\AppData\Local\Temp> .\kubectl.exe apply -f C:\Users\sysadmin\source\repos\RecruitManage\webapp-pod.yaml

Note : careful about that kubectl use .\kubectl.exe which is inside the folder not the plain kubectl because it will fall back to Docker's kubectl as it is set in environment variable.

KlausTrikk commented 5 years ago

@vinothrao, thank you, this solved my problem!

I've downloaded the newest kubectl.exe using the link above and replaced the old one (C:\Program Files\Docker\Docker\resources\bin\kubectl.exe) with it and it works for me!

Thanks a lot!

ktsakalozos commented 5 years ago

We can consider this issue resolved. Feel free to reopen if you have the same issue.

360cloud commented 5 years ago

wasted one good hour on this issue ,never thought that a kubectl version is issue . kubectl upgrade fixed it .

avanindra1 commented 5 years ago

hi i found error: error: SchemaError(io.k8s.api.core.v1.StorageOSVolumeSource): invalid object doesn't have additional properties.
while performing kubernetes deployment in CircleCI

CalvinHartwell commented 4 years ago

Hitting this error again with kubectl v1.6.3 and microk8s v1.6.3.

ktsakalozos commented 4 years ago

@CalvinHartwell could you share the microk8s.inspect tarball?

CalvinHartwell commented 4 years ago

@CalvinHartwell could you share the microk8s.inspect tarball?

Hey Kos,

We figured it out. At first, I was confused because I've seen errors when the version of kubernetes is different than the version of kubectl used, due to the fact api entries change between versions. A recent example in Kubernetes 1.16/1.15 was the graduation of the Deployment object from apiVersion: extensions/v1beta1 -> apiVersion: extensions/v1 (stable).

Our test platform is as follows:

We worked out that whenever we did not use kubectl with the full path we hit errors when trying to create Deployment objects, either using apply with a pre-created yaml manifest or using kubectl create deployment, both times it failed. We were using kubectl by appending it's path to the main path variable on windows (as per usual).

The message from vinothrao gave this away:

This has happened to me because of wrong version of kubectl installed by docker in the path "C:\Program Files\Docker\Docker\resources\bin" .

I resolved this by following below steps

Install kubectl manually by :

Install-Script -Name install-kubectl -Scope CurrentUser -Force install-kubectl.ps1 [-DownloadLocation ]

(https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-windows)

CD to the [-DownloadLocation ] folder and run kubectl from here . If the location is not given it will install it in temp by default. I have installed it in temp PS C:\Users\sysadmin\AppData\Local\Temp> : .\kubectl.exe version

If the version mismatch run the command again and check. Try kubectl apply from this location.

PS C:\Users\sysadmin\AppData\Local\Temp> .\kubectl.exe apply -f C:\Users\sysadmin\source\repos\RecruitManage\webapp-pod.yaml

Note : careful about that kubectl use .\kubectl.exe which is inside the folder not the plain kubectl because it will fall back to Docker's kubectl as it is set in environment variable.

I've created a bug here for kubectl: https://github.com/kubernetes/kubectl/issues/777

I do not think this issue is directly caused by multipass or microk8s, it is a kubectl bug.

Cheers,

mm986 commented 4 years ago

@CalvinHartwell Thank You! I was also facing same issue and got solved. It was because of following version differences between client and server: Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e9f0eaead", GitTreeState:"clean", BuildDate:"2018-03-26T16:55:54Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"windows/amd64"} Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.5", GitCommit:"20c265fef0741dd71a66480e35bd69f18351daea", GitTreeState:"clean", BuildDate:"2019-10-15T19:07:57Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"linux/amd64"}

I have updated kubectl.exe to match server dependency and now it's working fine:)