Kubernetes create deployment unexpected SchemaError
Asked Answered
W

18

73

I'm following that tutorial (https://www.baeldung.com/spring-boot-minikube) I want to create Kubernetes deployment in yaml file (simple-crud-dpl.yaml):

apiVersion: apps/v1
kind: Deployment
metadata:
  name: simple-crud
spec:
  selector:
      matchLabels:
        app: simple-crud
  replicas: 3
  template:
    metadata:
      labels:
        app: simple-crud
    spec:
      containers:
        - name: simple-crud
          image: simple-crud:latest
          imagePullPolicy: Never
          ports:
            - containerPort: 8080

but when I run kubectl create -f simple-crud-dpl.yaml i got: error: SchemaError(io.k8s.api.autoscaling.v2beta2.MetricTarget): invalid object doesn't have additional properties

I'm using the newest version of kubectl:

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

I'm also using minikube locally as it's described in tutorial. Everything is working till deployment and service. I'm not able to do it.

Waitabit answered 29/3, 2019 at 12:25 Comment(4)
I'd usually expect to see a line apiVersion: v1; does adding that help?Uproar
Result is still the same for others apiVersionBasque
have you tried linting the yaml? Sometimes that helps resolve some subtle formatting errors.Tulle
I just setup minikube on mac and am running into a similar issue in another tutorial that uses a remote file. My error is slightly different: kubectl create -f https://raw.githubusercontent.com/kelseyhightower/kubernetes-initializer-tutorial/master/deployments/helloworld.yaml error: SchemaError(io.k8s.api.core.v1.DaemonEndpoint): invalid object doesn't have additional properties I'm guessing something is messed up with our kubectl setup somewhereArginine
F
153

After installing kubectl with brew you should run:

  1. rm /usr/local/bin/kubectl

  2. brew link --overwrite kubernetes-cli

And also optionally:

brew link --overwrite --dry-run kubernetes-cli.

Fard answered 7/4, 2019 at 21:56 Comment(3)
can you explain what this is doing please?Nutation
Its worked for me also Do you know the reason behind of this?Selfdenial
what's the reason for re-linking?Cosimo
D
33

I second @rennekon's answer. I found that I had docker running on my machine which also installs kubectl. That installation of kubectl causes this issue to show.

I took the following steps:

  • uninstalled it using brew uninstall kubectl
  • reinstalled it using brew install kubectl
  • (due to symlink creation failure) I forced brew to create symlinks using brew link --overwrite kubernetes-cli

I was then able to run my kubectl apply commands successfully.

Delora answered 31/3, 2019 at 5:21 Comment(1)
same, but it was gcloud tools which had installed their own, out-of-date relative to the cluster i was targeting, kubectlUltimo
P
31

I too had the same problem. In my Mac system kubectl is running from docker which is preinstalled when I install Docker. You can check this by using below command

ls -l $(which kubectl) 

which returns as

/usr/local/bin/kubectl -> /Applications/Docker.app/Contents/Resources/bin/kubectlcode.

Now we have to overwrite the symlink with kubectl which is installed using brew

rm /usr/local/bin/kubectl

brew link --overwrite kubernetes-cli

(optinal)

brew unlink kubernetes-cli && brew link kubernetes-cli

To Verify

ls -l $(which kubectl)
Pedropedrotti answered 18/4, 2019 at 1:29 Comment(0)
T
26

I encountered the same issue on minikube/ Windows 10 after installing Docker. It was caused by the version mismatch of kubectl that was mentioned a couple of times already in this thread. Docker installs version 1.10 of kubectl.
You have a couple of options:

1) Make sure the path to your k8s bin is above the ones in docker
2) Replace the kubectl in 'c:\Program Files\Docker\Docker\resources\bin' with the correct one

Territoriality answered 6/4, 2019 at 7:52 Comment(1)
Fixed it for me, I just ran where kubectl at the command line to verify that was the version being used by default then curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.15.0/bin/windows/amd64/kubectl.exe to get the latest one.Glabella
P
12

Your client version is too old. In my env this version comes with Docker. I have to download new client from https://storage.googleapis.com/kubernetes-release/release/v1.14.0/bin/windows/amd64/kubectl.exe and now works fine:

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:"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"}
Palladic answered 5/4, 2019 at 10:13 Comment(2)
Same for me, just replaced the exe and now all is fineCita
Seems more relevant than the accepted answer. It answers both "what" and "why".Fishhook
S
7

You can use "--validate=false" in your command. For example:

kubectl create -f simple-crud-dpl.yaml --validate=false
Shaikh answered 29/6, 2019 at 21:23 Comment(1)
Thanks, this worked for me!!! Also work with: kubectl apply -f filename.yaml --validate=falseOrthoscope
C
5

You are using the wrong kubectl version.

Kubectl is compatible 1 version up and down as described in the official docs

The error is confusing but it simply means that your version 1.10 isn't sending all the required parameters to the 1.14 api.

Cilka answered 5/4, 2019 at 11:25 Comment(0)
A
2

I am on Windows 10 with Docker Client and Minikube both installed. I was getting the error below;

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

I resolved it by updating the version of kubectl.exe to that being used by minikube. Here are the steps:

Note: Minikube tends to use the latest version of Kubernetes so it will be advisable to grab the latest kubectl.

  1. Download the matching version of kubectl.exe.

  2. Navigate to your Docker path where your kubectl is located e.g. C:\Program Files\Docker\Docker\resources\bin

  3. Place your downloaded kubectl.exe there. If it asks you replace it, please do.

  4. Now type refreshenv in Powershell.

  5. Check the new version if it's what you have placed there; kubectl version.

Now you are good, retry whatever tasks you was doing.

Appall answered 13/6, 2019 at 10:43 Comment(0)
W
2

I was getting below error while running kubectl explain pod on windows 10

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

I had both Minikube and Docker Desktop installed. Reason for this error, as mentioned in earlier answers as well, was mismatch between server (major 1 minor 15) and client version (major 1 minor 10). Client version was coming from Docker Desktop. To fix I upgraded kubectl client version to v1.15.1 as described here

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.15.1/bin/windows/amd64/kubectl.exe
Wyler answered 28/7, 2019 at 7:33 Comment(0)
D
2

Mac user !!! This is for those who installed docker desktop first. The error will show up when you use the apply command. The error comes for a version miss match as some people said here. I did not install kubectl using homebrew. Rather kubectl auto get install when you install docker desktop for mac.

To fix this what I have done is bellow: Remove the kubectl executable file

rm /usr/local/bin/kubectl

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

Change the permission:

chmod +x ./kubectl

Move the executable file :

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

That is it folks! Just to show it worked here is the output:

kubectl apply -f ./deployment.yaml
deployment.apps/tomcat-deployment created

Make sure the yml file is correct. I downloaded a valid file from here to test : https://github.com/LevelUpEducation/kubernetes-demo/tree/master/Introduction%20to%20Kubernetes/Your%20First%20k8s%20App

Dalessandro answered 31/8, 2019 at 21:18 Comment(0)
A
1

Was running into the same issue after installing kubectl on my Mac today. Uninstalling kubectl [via brew uninstall kubectl] and reinstalling [brew install kubectl] resolved the issue for me.

Arginine answered 30/3, 2019 at 21:28 Comment(0)
I
1

According to the kubectl docs,

You must use a kubectl version that is within one minor version difference of your cluster.

kubectl v1.10 client apparently makes requests to kubectl v1.14 server without some newly (in 4 minor versions) required parameters.

For brew users, reinstall kubernetes-cli. It's worth checking what installed the incompatible version. For brew users, check the command symlink ls -l $(which kubectl).

Impermanent answered 8/4, 2019 at 20:10 Comment(0)
B
1

For me Docker installation was the problem. As Docker now comes with Kubernetes support, it installs kubectl along with its own installation. I had downloaded kubectl and minikube without knowing it, then my minikube was being used by Docker's kubectl installation.

Make sure that it is not also happening with you.

A second cause would be a deprecated apiVersion in your .yaml files.

Barrio answered 14/4, 2019 at 15:18 Comment(0)
E
1

I had a similar problem with error

error: SchemaError(io.k8s.api.storage.v1beta1.CSIDriverList): invalid object doesn't have additional properties

My issue was that my mac was using google's kubectl that was installed with the gcp tools. My path looks there first before going into /usr/local/bin/

Once I run kubectl from /usr/local/bin my problem went away.

Etherize answered 21/4, 2019 at 4:59 Comment(0)
S
1

In my case, kubectl is always using google's kubectl by gcloud tool, or there was most probably a conflict between Homebrew installed and Gcloud Installed kubectl. I uninstalled Homebrew kubectl and upgrade gcloud tool to the latest, which eventually upgrades the kubectl also in the process. It resolved my issue.

Stoller answered 12/5, 2019 at 7:17 Comment(0)
M
0

I don't think the problem is with imagePullPolicy, unless you don't have the image locally. The error is about autoscaling, which means it's not able to create replicas of the container.

Can you set replicas: 1 and give it a try?

Monagan answered 30/3, 2019 at 4:54 Comment(0)
E
0

On windows 10.0, uninstalling Docker helped me get away this problem. Doing with kubectl and minikube.

Ensemble answered 15/7, 2019 at 9:0 Comment(0)
C
0

I know this has already been answered but I though I should post my response since the responses above were helpful but it took me a while to relate it to Azure Dev Ops.

I was getting this error when I was trying to deploy an app to a AKS cluster from Azure Devops. As mentioned above, one of the issues this error could appear is because of version mismatch which was the cause in my case. I fixed it by updating my AKS version into the kubectl advanced configuration section as shown in the figure below

Azure Dev Ops screenshot

Cohbert answered 21/5, 2020 at 21:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.