-1

I'm following this Microsoft Tutorial to create a Windows Server container on an Azure Kubernetes Service (AKS) cluster using Azure Cli. In the Run the Application section of this turorial, I get the following error when running the following command to deploy the application using YAML config file:

kubectl apply -f sample.yaml

error: error validating "sample.yaml": error validating data: apiVersion not set; if you choose to ignore these errors, turn validation off with --validate=false

Question: As shown in the following sample.yaml file, the apiVersion is already set. So what this error is about and how can we fix the issue?

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
nam
  • 21,967
  • 37
  • 158
  • 332

3 Answers3

1

Issue resolved. The issue was related to copy/paste to Azure Cloud Shell. When you copy/paste content to vi editor in Azure Cloud Shell and if the content's first letter happens to be a then following may happen:

when opened vi in read mode, then by pasting, the first a may put user in edit mode and may not actually get that a inserted in the editor. So, in my case the content was pasted as follows (I'm only showing the first few lines here for brevity). So you notice here a was missing in the first line apiVersion: apps/v1 below:

sample.yaml file:

piVersion: apps/v1
kind: Deployment
metadata:
…..
...
nam
  • 21,967
  • 37
  • 158
  • 332
0

This happens when you use an outdated kubectl. Can you try updating to 1.2.5 or 1.3.0 and run it again

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • I'm using `Azure Cloud Shell` that has `Kubectl` already installed (probably by Microsoft). I assume they have the latest version installed. Or may be not. How do I find out the Kubectl version in Azure Cloud Shell? I followed the first paragraph of [this](https://learn.microsoft.com/en-us/azure/aks/windows-container-cli#connect-to-the-cluster) section of the tutorial. – nam Dec 20 '19 at 16:22
  • run kubectl version – Sajeetharan Dec 20 '19 at 16:24
  • I'm getting the following output. How do I upgrade to the latest version? `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"}` – nam Dec 20 '19 at 16:35
  • https://stackoverflow.com/questions/53701151/how-to-upgrade-kubectl-client-version – Sajeetharan Dec 20 '19 at 16:36
  • It seems Microsoft keeps their Azure Cloud Shell tools updated as explained in the second checkmark [here](https://azure.microsoft.com/en-us/features/cloud-shell/). And as explained [here](https://stackoverflow.com/a/55583899/1232087) we do not need to install the kubectl for AKS if you use the Azure Cloud Shell, that's a default tool installed in it. – nam Dec 20 '19 at 16:55
0

I fixed it in my case! For more context, feel free to visit here.

Summary:

If there is any file in which you are applying the yaml configs as follows:

kubectl apply -f .

then change that to the following:

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

Basically, apply configs separately with each file.

vagdevi k
  • 1,478
  • 9
  • 25