【问题标题】:ror: error validating "deployment.yaml": error validating data: the server could not find the requested resource;ror:验证“deployment.yaml”时出错:验证数据时出错:服务器找不到请求的资源;
【发布时间】:2019-11-14 19:21:58
【问题描述】:

我写了一个简单的Deploymnet yaml,它失败并出现错误

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

这曾经在以前的版本中工作,如果我打开 --validate=false 它仍然有帮助,但我想了解为什么会出现错误。

我的 deployment.yaml 文件

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"

我在 minikube 上运行 thsi,minikube 版本是: minikube 版本:v1.2.0

对于创建部署 yaml 文件的新版本,我们是否需要遵循任何标准。

除了这些警告之外没有显示任何错误,因此排除故障变得很痛苦。

如果有什么可以帮我解决的,请帮忙。

谢谢

【问题讨论】:

    标签: kubernetes google-kubernetes-engine kubernetes-helm kubectl minikube


    【解决方案1】:

    这是 kubectl 验证将要发送到 API 服务器而不是 Minikube 本身的内容的问题。

    错误出现在缩进中,因为 cpumemory 属性应该嵌套在请求中,而在资源中:

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

    我用 kubectl v1.15.0 测试过,错误显示正确:

    $ 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
    

    【讨论】:

    • kubectl apply -f test.yaml。编辑了我的答案以包含此内容。
    猜你喜欢
    • 2021-08-07
    • 2020-01-29
    • 2017-06-23
    • 2018-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-24
    相关资源
    最近更新 更多