0

When I try to execute this command kubectl apply -f mydeployment.yaml I receive an error error: SchemaError(io.k8s.api.core.v1.ContainerState): invalid object doesn't have additional properties. What can I do to deploy my aspnetcore webapi successfully to my local Kubernetes cluster?

I've already tried to upgrade minikube by running the command choco upgrade minikube. It says I've already have te latest version. minikube v1.0.0 is the latest version available based on your source(s).

My deployment.yaml I've created looks like this.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app
  labels:
    app: app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: app
  template:
    metadata:
      labels:
        app: app
    spec:
      containers:
        name: myfirstdockerapi
        image: myfirstdockerapi
        ports:
        - containerPort: 80
Marcel Beeker
  • 163
  • 1
  • 13
  • Please add the `mydeployment.yaml` to the question. It seems like there is a syntax error (probably due to YAML indentation) – Thomas Apr 21 '19 at 08:17
  • iVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: myfirstdockerapi image: myfirstdockerapi ports: - containerPort: 80 – Marcel Beeker Apr 21 '19 at 09:11
  • Please add it to the question as indented YAML, otherwise it is hard to spot possible problems – Thomas Apr 21 '19 at 13:25
  • I've added the content of my yaml file in my question in a more readable format. I hope you can help me. I struggle a few days to let it worl. – Marcel Beeker Apr 21 '19 at 18:43

2 Answers2

0

The containers element expects a list, so you need to prefix each entry with a dash.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app
  labels:
    app: app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: app
  template:
    metadata:
      labels:
        app: app
    spec:
      containers:
      - name: myfirstdockerapi
        image: myfirstdockerapi
        ports:
        - containerPort: 80

If you are unsure you can always use kubectl to validate your file without creating it: kubectl apply -f sample.yaml --validate --dry-run Just in case make sure that your kubectl version matches the version of your kubernetes cluster.

Poshi
  • 5,332
  • 3
  • 15
  • 32
Thomas
  • 11,272
  • 2
  • 24
  • 40
  • Unfortunately, your sugestion doesn't solve my problem. The error remains. Even when I tested it with the dry-run option I receive the same error. Checking the version of kubectl it results in version v1.10.11 of the client and v1.14.0 on the server. So, I think the problem is an incorrect version of the kubectl version and the version of my kubernetes cluster? Is that right? In that case, I don't know how to upgrade my client version to v1.14.0. Can you help me? – Marcel Beeker Apr 21 '19 at 21:46
  • Try removing and recreating the deployment: kubectl delete -f mydeployment.yaml and the apply it again. Seems to be some weird state. – Thomas Apr 21 '19 at 21:52
  • When I excute kubectl delete -f deployment.yaml. It results in this error: Error from server (NotFound): error when stopping "deployment.yaml": deployments.extensions "app" not found – Marcel Beeker Apr 21 '19 at 22:08
0


Cleanup everything before you start:

rm -rf ~/.minikube

As per documentation:

You must use a kubectl version that is within one minor version difference of your cluster. For example, a v1.2 client should work with v1.1, v1.2, and v1.3 master. Using the latest version of kubectl helps avoid unforeseen issues.

Minikube resources on Github you can find here:

To avoid interaction issues - Update default Kubernetes version to v1.14.0 #3967 NOTE: , we also recommend updating kubectl to a recent release (v1.13+)

For the latest version of minikube please follow official documentation here.

Kubernetes blog - here,
Stackoverlow here,
Choco here,

In the attached deployment there was indentation problem (corrected) so please try again.

spec:
  containers:
  - name: myfirstdockerapi
    image: myfirstdockerapi
    ports:
    - containerPort: 80
Mark
  • 3,644
  • 6
  • 23
  • I don't know how to UK update the client version of Kubectl. I think I have to replace the existing version by a newer version somewhere. How do I have to do that? – Marcel Beeker May 01 '19 at 21:28
  • Hi, did you follow instructions how do do it? "Install and Set Up kubectl". Please cleanup to start fresh install: `- rm -rf ~/.minikube`, `rm -rf ~/.kube`. Please folllow the instructions to install - kubectl (using curl and binary file, Powershell, Choco) [here](https://kubernetes.io/docs/tasks/tools/install-kubectl/) like this `curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.14.0/bin/windows/amd64/kubectl.exe` – Mark May 02 '19 at 07:39
  • Finally I've update my client version of Kubectl by enter this command in my browser: https://storage.googleapis.com/kubernetes-release/release/v1.14.0/bin/windows/amd64/kubectl.exe Kubectl is downloaded. But I want to overwrite the existing version of Kubectl. How can I do that? – Marcel Beeker May 05 '19 at 20:08
  • According to the documentation installing kubectl on Windows ad linux [here](https://kubernetes.io/docs/tasks/tools/install-kubectl/). Using powershell `Note: Updating the installation is performed by rerunning the two commands listed in step 1.` In addition you can follow instructions from this if you are using windows OS [tutorial](https://medium.com/@ggauravsigra/install-kubectl-on-windows-af77da2e6fff). – Mark May 06 '19 at 07:14
  • I've already found that documentation. I downloaded the newest version of kubectl I created a new directory C:\Kube, placed it in the path of my user system variables. But when I executed kubectl version in a different directory I still receive Major:"1", Minor:"10" of my client version. Something is wrong with some of my path settings. – Marcel Beeker May 06 '19 at 18:16
  • In case you have other issues with your env please remove all your _kubectl_ binaries, all installed other exec version and install new one: Stop your instances, and delete the .kube as an example `C:\>choco uninstall kubectl` you can find also more information [here](https://stackoverflow.com/questions/53263586/how-to-completely-uninstall-minikube-in-windows-10-pro-chocolatey) – Mark May 08 '19 at 06:20