验证数据时出错:服务器找不到请求的资源; [英] error validating data: the server could not find the requested resource;

查看:77
本文介绍了验证数据时出错:服务器找不到请求的资源;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行Pod时出现以下错误.我与Kubernetes网页中的文档匹配,它的代码与我在下面编写的代码相同,但最终还是出现以下错误.

I'm seeing the following error when running a pod. I matched with the documentation in the Kubernetes webpage and it is the code is same as the one i have written below but Istill end up with the below error.

错误验证数据:服务器找不到请求的资源;如果您选择忽略这些错误,请使用--validate = false

error validating data: the server could not find the requested resource; if you choose to ignore these errors, turn validation off with --validate=false

apiVersion: v1
kind: pod
metadata:
  name: helloworld-deployment
  labels:
    app: helloworld
spec:
  containers:
  - name: helloworld
    image: anishanil/kubernetes:node
    ports:
      containerPort: 3000
     resources:
      limits:
        memory: "100Mi"
        cpu: "100m"


Client Version: version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.1", GitCommit:"b0b7a323cc5a4a2019b2e9520c21c7830b7f708e", GitTreeState:"clean", BuildDate:"2017-04-03T20:44:38Z", GoVersion:"go1.7.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.6+IKS", GitCommit:"44b769243cf9b3fe09c1105a4a8749e8ff5f4ba8", GitTreeState:"clean", BuildDate:"2019-08-21T12:48:49Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}


非常感谢您的帮助


Any help is greatly appreciated

谢谢

推荐答案

我与Kubernetes网页中的文档匹配,它是该代码与我在下面编写的代码相同...

I matched with the documentation in the Kubernetes webpage and it is the code is same as the one i have written below...

您可以链接与代码进行比较的文档片段吗?正如其他人在其答案和评论中已经建议的那样,您的 yaml 无效.您确定不使用一些过时的教程或文档吗?

Could you link the fragment of documentation with which you compare your code ? As other people already suggested in their answers and comments, your yaml is not valid. Are you sure you're not using some outdated tutorial or docs ?

让我们逐步对其进行调试:

  1. 当我使用与您在问题中发布的代码完全相同时,我收到的错误消息与您发布的代码完全不同:

错误:解析pod.yml时发生错误:将YAML转换为JSON时发生错误:yaml:第12行:找不到预期的密钥

error: error parsing pod.yml: error converting YAML to JSON: yaml: line 12: did not find expected key

好,让我们转到第12行,检查问题出在哪里:

OK, so let's go to mentioned line 12 and check where can be the problem:

 11     ports:
 12       containerPort: 3000
 13      resources:
 14       limits:
 15         memory: "100Mi"
 16         cpu: "100m"

第12行本身看起来完全没问题,因此问题应该出在其他地方.让我们使用在线Yaml验证程序进行进一步调试.这也表明此 yaml 在语法上是不正确的,但是它指出了不同的行:

Line 12 itself looks actually totally ok, so the problem should be elsewhere. Let's debug it further using this online yaml validator. It also suggests that this yaml is syntactically not correct however it pointed out different line:

():在解析块映射时未找到预期的密钥在第9行的第5列

(): did not find expected key while parsing a block mapping at line 9 column 5

如果仔细看一下上面引用的代码片段,您可能会注意到第13行的缩进级别看起来很奇怪.当您在 resources 之前删除一个不必要的空间(它应该与端口位于同一级别)时

If you look carefully at the above quoted fragment of code, you may notice that the indentation level in line 13 looks quite strange. When you remove one unnecessary space right before resources ( it should be on the same level as ports ) yaml validador will tell you that your yaml syntax is correct. Although it may already be a valid yaml it does not mean that it is a valid input for Kubernetes which requires specific structure following certain rules.

  1. 让我们再试一次...现在 kubectl apply -f pod.yml 返回完全不同的错误:
  1. Let's try it again... Now kubectl apply -f pod.yml returns quite different error:

来自服务器的错误(BadRequest):创建"pod.yml"时出错:pod in版本"v1"不能作为Pod处理:未注册任何种类的"pod"方案中的版本"v1""k8s.io/kubernetes/pkg/api/legacyscheme/scheme.go:29"

Error from server (BadRequest): error when creating "pod.yml": pod in version "v1" cannot be handled as a Pod: no kind "pod" is registered for version "v1" in scheme "k8s.io/kubernetes/pkg/api/legacyscheme/scheme.go:29"

快速搜索也会为您提供答案. kind:键的正确值是 Pod ,而不是 pod .

Quick search will give you an answer to that as well. Proper value of kind: key is Pod but not pod.

  1. 修复该问题后,让我们再次运行 kubectl apply -f pod.yml .现在它给了我们不同的错误:
  1. Once we fixed that, let's run kubectl apply -f pod.yml again. Now it gives us back different error:

错误:验证"pod.yml"时出错:验证数据时出错:ValidationError(Pod.spec.containers [0] .ports):的无效类型io.k8s.api.core.v1.Container.ports:已获取地图",预期为数组";

error: error validating "pod.yml": error validating data: ValidationError(Pod.spec.containers[0].ports): invalid type for io.k8s.api.core.v1.Container.ports: got "map", expected "array";

这很容易解释,这意味着您不应在预期会出现"array" 且错误消息准确的地方使用"map" 指出哪里,即:

which is pretty self-explanatory and means that you are not supposed to use "map" in a place where an "array" was expected and the error message precisely pointed out where, namely:

Pod.spec.containers [0] .ports .

让我们纠正这个片段:

11     ports:
12       containerPort: 3000

在yaml格式中,-字符表示数组的开始,因此应如下所示:

In yaml formatting the - character implies the start of an array so it should look like this:

11     ports:
12     - containerPort: 3000

  1. 如果再次运行 kubectl apply -f pod.yml ,我们最终会得到预期的消息:
  1. If we run kubectl apply -f pod.yml again, we finally got the expected message:

pod/helloworld-deployment已创建

pod/helloworld-deployment created

Pod 定义的最终正确版本如下:

The final, correct version of the Pod definition looks as follows:

apiVersion: v1
kind: Pod
metadata:
  name: helloworld-deployment
  labels:
    app: helloworld
spec:
  containers:
  - name: helloworld
    image: anishanil/kubernetes:node
    ports:
    - containerPort: 3000
    resources:
      limits:
        memory: "100Mi"
        cpu: "100m"

这篇关于验证数据时出错:服务器找不到请求的资源;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆