44

When I try any kubectl command, it always returns:

Unable to connect to the server: EOF

I followed these tutorials:

https://kubernetes.io/docs/tasks/tools/install-kubectl/

https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/

But they have not helped me. According to the first link, by default, kubectl configuration is located at

~/.kube/config

But in that path I don't have anything. I don't know if this is causing the issue.

Other thing is when I try to check the kubectl configuration:

M:.kube candres$ kubectl cluster-info
Kubernetes master is running at http://localhost:8080

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
Unable to connect to the server: EOF
M:.kube candres$ kubectl cluster-info dump
Unable to connect to the server: EOF

The versions I have installed are:

Kubernetes - kubectl

M:.kube candres$ kubectl version
Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.3", GitCommit:"X", GitTreeState:"clean", BuildDate:"2018-02-09T21:51:06Z", GoVersion:"go1.9.4", Compiler:"gc", Platform:"darwin/amd64"}
Unable to connect to the server: EOF

Minikube

M:.kube candres$ minikube version
minikube version: v0.25.0

Docker:

M:.kube candres$ docker version
Client:
 Version:   17.12.0-ce
 API version:   1.35
 Go version:    go1.9.2
 Git commit:    X
 Built: Wed Dec 27 20:03:51 2017
 OS/Arch:   darwin/amd64

Server:
 Engine:
  Version:  17.12.0-ce
  API version:  1.35 (minimum version 1.12)
  Go version:   go1.9.2
  Git commit:   X
  Built:    Wed Dec 27 20:12:29 2017
  OS/Arch:  linux/amd64
  Experimental: true

Does anyone know how to resolve this?

MrMister
  • 2,456
  • 21
  • 31
Carlos Andres
  • 12,740
  • 7
  • 18
  • 34
  • Hi @Carlos, It's quite an odd behaviour that one of the command `kubectl cluster-info` is working. However, others are not working. Could you please run following command `kubectl config view` which will list all of the clusters and contexts. – Suresh Vishnoi Feb 22 '18 at 13:20
  • btw, Port number for API Server is 8443 or 443. Why the port number is 8080 ? – Suresh Vishnoi Feb 22 '18 at 13:21
  • Hi @SureshVishnoi! When I run that command, that return: `M:.kube candres$ kubectl config view apiVersion: v1 clusters: [] contexts: [] current-context: "" kind: Config preferences: {} users: []` With regard about the port, I dont know why this use port 8080! – Carlos Andres Feb 22 '18 at 13:25
  • It means kubectl does not know about k8s API server. IF it does not know about the api server. It won't be able to do anything – Suresh Vishnoi Feb 22 '18 at 13:27
  • Hi Following link will give your comprehensive detail [kubeconfig file](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/) – Suresh Vishnoi Feb 22 '18 at 13:29
  • 1
    As you are using minikube , As far as I know, Minikube configure `kubeconfig` file automatically. So You can restart the minikube. You can run `minikube status` to verify it. – Suresh Vishnoi Feb 22 '18 at 13:33
  • Hi, let me know if you still face the same issues. – Suresh Vishnoi Feb 22 '18 at 13:42
  • @SureshVishnoi ! With your help I fix my issue. The issue was than I dont start the minikube. So, later do this: `minikube start` With this, my machine come to download the ISO of minikube. Then `M:.kube candres$ kubectl cluster-info Kubernetes master is running at https://192.168.99.100:8443` Thanks a lot ! – Carlos Andres Feb 22 '18 at 13:47
  • Glad it worked. I will post the answer and we can close the question. – Suresh Vishnoi Feb 22 '18 at 13:48

10 Answers10

24

After Minikube is started, kubectl is configured automatically.

minikube start
Starting local Kubernetes cluster...
Kubernetes is available at https://192.168.99.100:8443.
Kubectl is now configured to use the cluster.

You can verify and validate the cluster and context with following commands.

kubectl config view
ghitesh
  • 160
  • 2
  • 14
Suresh Vishnoi
  • 17,341
  • 8
  • 47
  • 55
5

I also had this issue. Be sure to check your config file that is generated by minikube. This file can most likely be found ~/.kube/config. Make sure that you are referencing the right cluster name in the current context you are using. You can see what context you are currently using by: kubectl get current-context. The important thing is that you understand why you are getting this error and as @Suresh Vishnoi stated, kubectl doesn't know about k8s api-server.

Nappstir
  • 995
  • 2
  • 20
  • 38
  • 2
    Writing this in 03Dec2020 while picking up Kubernetes and `kubectl get current-context` doesn't work. View current context with `kubectl config current-context` instead – Jonalogy Dec 03 '20 at 05:51
2

here the steps to my solution

  1. Install minikube:

brew install minikube

  1. Start minikube

minikube start

  1. check again and ✅

kubectl version --short

Client Version: v1.16.6-beta.0

Server Version: v1.22.2

Junior Vieira
  • 553
  • 5
  • 5
  • Flag --short has been deprecated, and will be removed in the future. The --short output will become the default. – Noam Nol Oct 24 '22 at 16:23
2

Here is all I had to run:

  • minikube delete
  • minikube start
Akintunde
  • 3,525
  • 1
  • 21
  • 23
1

Just updating Kubectl version to latest version resolve my problem.

1

If you get a message like this:

You appear to be using a proxy, but your NO_PROXY environment does not include the minikube IP (www.xxx.yyy.zzz).

Then set your environment variable NO_PROXY to the address given before running kubectl. This is probably configurable somewhere, but that's a short quick solution.

Ken
  • 11
  • 1
  • this is the point for me. Here is my config in ~/.zshrc: ``` bash export http_proxy=http://192.168.168.168:1087; export https_proxy=http://192.168.168.168:1087; export no_proxy="10.0.0.0/8,localhost,127.0.0.1,192.168.0.0/16" ``` – terry zhang Dec 04 '21 at 13:43
1
reset kubeadm via force

reset kubeadm -f

and then copy config file again

cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

at last

kubectl init
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Fox
  • 11
  • 2
0

I'm using wsl. So it helps me to synchronize time between windows and linux console.

sudo hwclock --hctosys 
Vlad Pavlovski
  • 1,582
  • 1
  • 14
  • 10
0

Check your VPN security as well as your anti virus internet security. in case it is ON then we have to make it off. and it worked for me after that.

Try it out this also.

Mohit Jariwal
  • 71
  • 1
  • 2
0

VPN should solve it, if not, then also try unsetting local env proxy settings.

Ajit Surendran
  • 709
  • 7
  • 4