kubectl error validating data: apiVersion not set (apiversion already set to v1)

Created on 25 Jun 2020  路  2Comments  路  Source: kubernetes/kubectl

while creating yaml file with kubectl i am getting error of apiversion not set. but i have already set it to v1.

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

cat myfirstpod.yaml
kind: Pod
apiversion: v1
metadata:
name: myfirstpod
spec:
containers:

  • name: container1
    image: aamirpinger/helloworld:latest
    ports:
  • containerPort: 80

i am using these versions
minikube version: v1.11.0
kubectl is version 1.8.4
Kubernetes 1.18.3
Docker 19.03.11

kinbug

All 2 comments

I did typo in writing apiversion instead of apiVersion. Issue is resolved.

In my case, I am deploying my project on GKE via Travis. In my travis file, I am calling a shell file (deploy.sh).

In the deploy.sh file, I have written all the steps to create kubernetes resources:

### Deploy

# Apply k8s config
kubectl apply -f .

So here, I replaced kubectl apply -f . with the individual file names as follows:

### Deploy

# Apply k8s config
kubectl apply -f namespace.yaml
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl apply -f ingress.yaml

And then, the error is fixed!

Was this page helpful?
0 / 5 - 0 ratings