Search code examples
kuberneteskubectl

How to fix kubectl Error from server (NotFound): the server could not find the requested resource


I was install kubectl by the official instruction, but when i've try kubectl apply -f i've get " Error from server (NotFound): the server could not find the requested resource " error.

The Internet says that it's because the Client and Server Version of kubectl is different.

I'll check the verision of kubectl:

Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.2", GitCommit:"59603c6e503c87169aea6106f57b9f242f64df89", GitTreeState:"clean", BuildDate:"2020-01-18T23:30:10Z", GoVersion:"go1.13.5", Compiler:"gc", Platform:"linux/amd64"}

Server Version: version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.4", GitCommit:"d6f433224538d4f9ca2f7ae19b252e6fcb66a3ae", GitTreeState:"dirty", BuildDate:"2017-06-22T04:31:09Z", GoVersion:"go1.7.5", Compiler:"gc", Platform:"linux/amd64"}

If it is official install, why version so different? And is it really problem of this error?

I also have docker, docker-compose and minikube.

OS Linux Mint


Solution

  • Posting Community Wiki as root cause was mentioned by @David Maze

    As was pointed in the comments, your versions are very different. Kubernetes 1.7 was realesed ~ July 2017, when Kubernetes 1.17 was released in Jan 2020 (almost 2,5 year difference). Another thing is version of Docker and Minikube must support kubernetes version.

    As Example, if you would like to run Kubernetes 1.6.3 on latest Minikube version, error occurs.

    minikube v1.7.3 on Ubuntu 16.04
    ✨  Using the none driver based on user configuration
    ⚠️  Specified Kubernetes version 1.6.4 is less than the oldest supported version: v1.11.10
    💣  Sorry, Kubernetes 1.6.4 is not supported by this release of minikube
    

    Also, there was huge change in apiVersions between version 1.15 and 1.16. More details can be found here.

    In this Stackoverflow thread was explained what is shown in kubectl version.

    The second line ("Server Version") contains the apiserver version.

    As for example Network Policy API was introduced in Kubernetes 1.7, so if you would like to use it in 1.6, you will get error as API cannot recognize it.

    I've reproduced your issue.

    minikube:~$ kubectl version
    Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.3", GitCommit:"06ad960bfd03b39c8310aaf92d1e7c12ce618213", GitTreeState:"clean", BuildDate:"2020-02-11T18:14:22Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"linux/amd64"}
    Server Version: version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.3", GitCommit:"0480917b552be33e2dba47386e51decb1a211df6", GitTreeState:"dirty", BuildDate:"2017-05-12T10:50:10Z", GoVersion:"go1.7", Compiler:"gc", Platform:"linux/amd64"}
    minikube:~$ kubectl get pods
    Error from server (NotAcceptable): the server was unable to respond with a content type that the client supports (get pods)
    minikube:~$ kubectl get nodes
    Error from server (NotAcceptable): the server was unable to respond with a content type that the client supports (get nodes)
    minikube:~$ kubectl run nginx --image=nginx
    WARNING: New generator "deployment/apps.v1" specified, but it isn't available. Falling back to "deployment/apps.v1beta1".
    kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
    error: no matches for kind "Deployment" in version "apps/v1"
    

    As I mentioned before, Network Policy was introduced in 1.7. When you will try apply this config from Official Kubernetes docs, it will show the same error you have.

    minikube:~$ kubectl apply -f network.yaml 
    Error from server (NotFound): the server could not find the requested resource.
    

    Most recommended way is to install newest versions of docker, kubernetes and minikube (security and newest features) based on Docker docs and Kubernetes kubectl docs and Minikube.

    Another option is to downgrade all components.