如何修复来自服务器的 kubectl 错误(NotFound):服务器找不到请求的资源

问题描述 投票:0回答:4

我按照官方说明安装了 kubectl,但是当我尝试

kubectl apply -f
时,我收到了“
Error from server (NotFound): the server could not find the requested resource 
”错误。

网上说是因为kubectl的Client和Server版本不同。

我会检查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"} 

如果是官方安装,为什么版本差别这么大?这真的是这个错误的问题吗?

我还有 docker、docker-compose 和 minikube。

操作系统 Linux Mint

kubernetes kubectl
4个回答
4
投票

@David Maze 提到将社区 Wiki 发布为根本原因

正如评论中所指出的,你们的版本非常不同。 Kubernetes 1.7 发布于 2017 年 7 月,当时 Kubernetes 1.172020 年 1 月发布(几乎相差 2.5 年)。另一件事是

Docker
的版本和
Minikube
必须支持
kubernetes
版本。

例如,如果您想在最新的

Minikube
版本上运行 Kubernetes 1.6.3,则会发生错误。

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

此外,1.15 和 1.16 版本之间

apiVersions
也发生了巨大的变化。更多详情请参阅这里

这个 Stackoverflow 线程 中解释了

kubectl version
中显示的内容。

第二行(“服务器版本”)包含 apiserver 版本。

例如

Network Policy API
是在Kubernetes 1.7中引入的,所以如果你想在1.6中使用它,你会得到错误,因为API无法识别它。

我已重现您的问题。

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"

正如我之前提到的,

Network Policy
是在1.7中引入的。当您尝试应用官方 Kubernetes 文档中的此配置时,它将显示与您相同的错误。

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

最推荐的方法是基于 Docker docsKubernetes kubectl docsMinikube 安装最新版本的 docker、kubernetes 和 minikube(安全性和最新功能)。

另一种选择是降级所有组件。


2
投票

降级您的 kubectl 版本。请提及您最初安装时遵循的官方文档。

sudo apt-get install -qy kubectl=1.16.3-00

第二点,我认为大卫是对的。也许你的清单中的 api 和 k8s 版本不匹配。


0
投票

如果运行

kubectl apply -f deployment.yaml
并收到“来自服务器的错误(未找到):服务器找不到请求的资源”,原因很可能是在deployment.yaml 中使用了已弃用的 API。

您在deployment.yaml 文件中使用的API 版本对于您的Kubernetes 版本可能已弃用。请查看官方指南以找到要使用的新版本 API:已弃用的 API 迁移指南


0
投票

我从服务器收到错误(未找到):kogitobuilds.rhpam.kiegroup.org“travels”未找到

我正在关注Kogito教程 https://docs.kogito.kie.org/latest/html_single/#_cloud_first_priority

© www.soinside.com 2019 - 2024. All rights reserved.