【问题标题】:YAML - Validation error during deployment using Yaml config fileYAML - 使用 Yaml 配置文件部署期间的验证错误
【发布时间】:2020-04-13 03:10:17
【问题描述】:

我正在关注this Microsoft 教程,以使用 Azure Cli 在 Azure Kubernetes 服务 (AKS) 集群上创建 Windows Server 容器。在本教程的 Run the Application 部分中,运行以下命令以使用 YAML 配置文件部署应用程序时出现以下错误:

kubectl apply -f sample.yaml

错误:验证“sample.yaml”时出错:验证数据时出错:未设置apiVersion;如果您选择忽略这些错误,请使用 --validate=false 关闭验证

问题:如下图sample.yaml文件所示,apiVersion已经设置好了。那么这个错误是关于什么的,我们该如何解决这个问题呢?

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sample
  labels:
    app: sample
spec:
  replicas: 1
  template:
    metadata:
      name: sample
      labels:
        app: sample
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": windows
      containers:
      - name: sample
        image: mcr.microsoft.com/dotnet/framework/samples:aspnetapp
        resources:
          limits:
            cpu: 1
            memory: 800M
          requests:
            cpu: .1
            memory: 300M
        ports:
          - containerPort: 80
  selector:
    matchLabels:
      app: sample
---
apiVersion: v1
kind: Service
metadata:
  name: sample
spec:
  type: LoadBalancer
  ports:
  - protocol: TCP
    port: 80
  selector:
    app: sample

【问题讨论】:

  • 我认为这是由于浏览器的错误粘贴,检查隐藏符号等

标签: azure kubectl azure-aks yaml-cpp


【解决方案1】:

我在我的情况下修复了它!如需了解更多信息,请随时访问here

总结:

如果有任何文件在其中应用 yaml 配置,如下所示:

kubectl apply -f .

然后将其更改为以下内容:

kubectl apply -f namespace.yaml
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl apply -f ingress.yaml

基本上,对每个文件单独应用配置。

【讨论】:

    【解决方案2】:

    问题已解决。该问题与复制/粘贴到Azure Cloud Shell 有关。当您将内容复制/粘贴到 Azure Cloud Shell 中的 vi 编辑器时,如果内容的第一个字母恰好是 a,则可能会发生以下情况:

    当以读取模式打开 vi 时,通过粘贴,第一个 a 可能会将用户置于编辑模式,并且实际上可能无法将 a 插入到编辑器中。因此,就我而言,内容粘贴如下(为简洁起见,我仅在此处显示前几行)。所以你注意到这里a 在下面的第一行apiVersion: apps/v1 中丢失了:

    sample.yaml 文件

    piVersion: apps/v1
    kind: Deployment
    metadata:
    …..
    ...
    

    【讨论】:

      【解决方案3】:

      当您使用过时的 kubectl 时会发生这种情况。你可以尝试更新到 1.2.5 或 1.3.0 并再次运行它吗

      【讨论】:

      • 我正在使用Azure Cloud Shell,它已经安装了Kubectl(可能由Microsoft 安装)。我假设他们安装了最新版本。或者可能不是。如何在 Azure Cloud Shell 中找到 Kubectl 版本?我按照教程的this部分的第一段。
      • 运行 kubectl 版本
      • 我得到以下输出。如何升级到最新版本? Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:36:53Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.8", GitCommit:"1da9875156ba0ad48e7d09a5d00e41489507f592", GitTreeState:"clean", BuildDate:"2019-11-14T05:19:20Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"linux/amd64"}
      • 微软似乎在更新其 Azure Cloud Shell 工具,如第二个复选标记 here 中所述。正如here 解释的那样,如果您使用 Azure Cloud Shell,我们不需要为 AKS 安装 kubectl,这是安装在其中的默认工具。
      猜你喜欢
      • 2018-01-17
      • 1970-01-01
      • 2019-04-06
      • 2020-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-13
      • 2020-07-10
      相关资源
      最近更新 更多