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
This happens when you use an outdated kubectl
. Can you try updating to 1.2.5 or 1.3.0 and run it again
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:
…..
...