ror: error validating "deployment.yaml": error validating data: the server could not find the requested resource;

7/4/2019

I wrote down a simple Deploymnet yaml and it fails with the error

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

This used to work in the previous versions and if i turn --validate=false it still helps but i would like to understand why the error is seen.

My deployment.yaml file

apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpd-deployment
  labels:
    app: httpd
spec:
  replicas: 1
  selector:
    matchLabels:
      app: httpd
  template:
    metadata:
      labels:
        app: httpd
    spec:
      containers:
      - name: httpd
        image: httpd:latest
        ports:
        - containerPort: 80
        resources:
          requests:
          cpu: "0.3"
          memory: "500Mi"

I'm running thsi on minikube and the minikube version is: minikube version: v1.2.0

Are there any standards that we need to follow for the new version for creating the deployment yaml file.

There are no errors that are displayed except these warning so Troubeshooting this is becoming a pain.

So if there is anything that can help me fix could you please help.

Thank you

-- anish anil
google-kubernetes-engine
kubectl
kubernetes
kubernetes-helm
minikube

1 Answer

7/4/2019

This is an issue with kubectl validating what is going to be sent into the API server rather than Minikube itself.

The error is in the indentation as cpu and memory properties should be nested within requests and not in resources:

spec:
      containers:
      - name: httpd
        image: httpd:latest
        ports:
        - containerPort: 80
        resources:
          requests:
            cpu: "0.3"
            memory: "500Mi"

I've tested it using kubectl v1.15.0 and the error was correctly displayed:

$ kubectl apply -f test.yaml
$ error: error validating "test.yaml": error validating data: [ValidationError(Deployment.spec.template.spec.containers[0].resources): unknown field "cpu" in io.k8s.api.core.v1.ResourceRequirements, ValidationError(Deployment.spec.template.spec.containers[0].resources): unknown field "memory" in io.k8s.api.core.v1.ResourceRequirements]; if you choose to ignore these errors, turn validation off with --validate=false
-- yyyyahir
Source: StackOverflow