error validating data: the server could not find the requested resource;

9/30/2019

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.


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

Thank you

-- anish anil
kubernetes
kubernetes-helm
kubernetes-ingress
kubernetes-pod

3 Answers

9/30/2019

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

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 ?

Let's debug it together step by step:

  1. When I use exactly the same code you posted in your question, the error message I got is quite different than the one you posted:

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

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"

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:

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

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. Let's try it again... Now kubectl apply -f pod.yml returns quite different error:

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"

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

  1. Once we fixed that, let's run kubectl apply -f pod.yml again. Now it gives us back different error:

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";

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.

Let's correct this fragment:

11     ports:
12       containerPort: 3000

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

11     ports:
12     - containerPort: 3000
  1. If we run kubectl apply -f pod.yml again, we finally got the expected message:

pod/helloworld-deployment created

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"
-- mario
Source: StackOverflow

9/30/2019

resources should be inline with image, name, ports in yaml definition. OR You can use below yaml.

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

9/30/2019

Your yaml has error. You can use a yaml validation tool to get it checked. Or use the below instead:

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