adminuser@containerVm:~$ cat pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app: nginx
tier: frontend
spec:
containers:
adminuser@containerVm:~$ kubectl apply -f pod.yaml
error: error validating “pod.yaml”: error validating data: failed to download openapi: Get “http://localhost:8080/openapi/v2?timeout=32s”: dial tcp 127.0.0.1:8080: connect: connection refused; if you choose to ignore these errors, turn validation off with --validate=false
How can we fix this ?
I don’t see any problem with your YAML (although please use the </>
key to generate code blocks for your YAML – it’s garbled if you don’t do that). One thing that might give you this problem is if your kubectl version and your cluster version aren’t sufficiently in sync. What do you get when you do
kubectl version
?
root@linuxvm2:/home/adminuser# kubectl version --client Client Version: v1.30.1
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
How can i fix the above error?
please just do kubectl version
; I need to see the server version too, and you gave me the client only.
root@linuxvm2:/home/adminuser# kubectl version
Client Version: v1.30.1
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
The connection to the server localhost:8080 was refused - did you specify the right host or port?
This machine is an azure VM
OK, that suggests that your kubeconfig file is either absent or invalid. First of all, you’ll need to get a kubeconfig file (I’m not sure how you do this in Azure) and you need to install it, or you’re not going to be able to do anything.
Assuming you just set up your Azure cluster, the version is probably 1.29, so that would be compatible with a 1.30 copy of kubectl. If your version is 1.28 or less – which is possible on Azure right now – it would not be, since you need to be 1 or less versions off from the server version for kubectl to work correctly.