【问题标题】:I'm getting error while running yaml file inside minkube by command "kubectl apply -f firstpod.yaml"通过命令“kubectl apply -f firstpod.yaml”在 minkube 中运行 yaml 文件时出现错误
【发布时间】:2021-01-12 10:05:59
【问题描述】:

这是我的 firstpod.yaml 文件:

apiVersion: v1
kind: Pod
metadata: 
 name: webapp
spec: 
 containers: 
 - name: webappcontainer 
   image: richardchesterwood/k8s-fleetman-webapp-angular:release0

   

我收到以下错误:

error: error validating "firstpod.yaml": error validating data: ValidationError(Pod.spec.containers[0]): invalid type for io.k8s.api.core.v1.Container: got "string", expected "map"; if you choose to ignore these errors, turn validation off with --validate=false"

在线解析器中 yaml 文件的 OUTPUT 格式看起来一切正常。您可以在下面看到在线解析器输出

{
  "kind": "Pod", 
  "spec": {
    "containers": [
      {
        "image": "richardchesterwood/k8s-fleetman-webapp-angular:release0", 
        "name": "webappcontainer"
      }
    ]
  }, 
  "apiVersion": "v1", 
  "metadata": {
    "name": "webapp"
  }
}

【问题讨论】:

    标签: kubernetes yaml kubectl minikube kubernetes-pod


    【解决方案1】:

    pod 的 yaml 语法应该如下所示

    apiVersion: v1
    kind: Pod
    metadata: 
      name: webapp
    spec: 
      containers: 
      - name: webappcontainer 
        image: richardchesterwood/k8s-fleetman-webapp-angular:release0
    

    【讨论】:

    • 你可以复制我的答案试试
    • 是的,我也通过复制尝试了您的答案,但得到了同样的错误。 @Arghya Sadhu
    • image声明为map,应为image: {richardchesterwood/k8s-fleetman-webapp-angular: release0}
    【解决方案2】:

    @Arghya Sadhu 提供的 yaml 就像一个魅力,它遵循所有 pod spec rules

    经过测试

    Win10
    minikube version: v1.12.2 commit: be7c19d391302656d27f1f213657d925c4e1cfc2-dirty
    kubectl 1.19
    

    在复制粘贴示例时仔细检查是否有正确的缩进,检查复制粘贴后是否有任何隐藏符号。 示例无处不在 - 在 Win+Mac minikubes、gke ans aws 中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-11
      • 2019-11-18
      • 2019-06-03
      • 2019-01-03
      • 1970-01-01
      • 2012-06-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多