0

I installed Kubernetes in virtual BOX previously it was working properly but not it is showing The connection to the server 192.168.42.141:6443 was refused - did you specify the right host or port?, Please help.

Dewa
  • 33
  • 1
  • 7
  • can you ensure your vBox `192.168.42.141` is ok. is it changed? or kube-apiserver is running on your vBox? – hoque May 28 '20 at 09:14
  • Have you tried restarting the minikube? Run: `minikube stop`, `minikube delete`, `minikube start`. – Wytrzymały Wiktor May 28 '20 at 12:01
  • Is kube-apiserver running on your cluster? – hariK May 28 '20 at 12:08
  • @harik how i can check api server is running or not. – Dewa May 29 '20 at 04:34
  • @hoque yes i checked ip is not changed.plz let me know how i can check api service is running or bot. – Dewa May 29 '20 at 04:35
  • @ohHiMark yes i tried to restart by using kubadm reset. – Dewa May 29 '20 at 04:36
  • run docker ps to check the running docker container of apiserver – hoque May 29 '20 at 06:03
  • @hoque thanks api was no running now it is running, but now when i run "kubectl create deployment firstpod --image=ubuntu" then getting error from the server(bot found ): the server coluld not find the requested resource. Plz help – Dewa May 31 '20 at 09:30
  • what is your kubernetes version? – hoque May 31 '20 at 10:09
  • @hoque: Please find the out put of kubectl version --short Client Version: v1.6.0 Server Version: v1.18.3 if any other details required plz let me know – Dewa Jun 02 '20 at 15:52
  • can you check updating you client version? – hoque Jun 02 '20 at 16:18
  • @hoque how i can update client version – Dewa Jun 02 '20 at 16:41
  • just install kubectl again https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-linux – hoque Jun 02 '20 at 17:15
  • ok. i am adding that as answer so that anyone facing the issue could see the answer – hoque Jun 03 '20 at 05:24
  • @Hoque, u were right there were client version mismatch find the below command output Command : kubectl version --short Output : Client Version: v1.6.0 & Server Version: v1.18.3 To Overcome from this i use Command : minikube kubectl -- version --short Output : Client Version: v1.18.3 & Server Version: v1.18.3 When we run this command minikube autometically download appropriate version of kubectl, so next time i can any command with "minikube kubectl --" for example Command : "minikube kubectl -- create deployment hello-minikube --image=abc" – Dewa Jun 03 '20 at 05:29

2 Answers2

1

The connection to the server 192.168.42.141:6443 was refused - did you specify the right host or port?

According to issue there might be kube-apiserver not running state. To check the apiserver status run following command

$ docker ps
# If above is not sowing apiserver container, then it is stopped, To see the stopped container run
$ docker ps -a

P.S: From the comment there is also a version mismatch. To update kubectl follow this

hoque
  • 5,735
  • 1
  • 19
  • 29
1

kubectl on any machine reads the current context from kubeconfig file. The file is located at the path $USER_HOME/.kube/config

There are clusters configured inside this file alongwith the IP or domain name of the cluster. If the IP is invalid or not reachable OR the domain name can not be resolved and is unreachable OR the config file is corrupted or the config file is empty, then this error occurs.

In brief, you need to check your config file. It will save you a lot of effort.

KnockingHeads
  • 1,569
  • 1
  • 22
  • 42