user10147267
user10147267

Reputation: 73

Kubernetes connection error in Mac

OS : OSX (mac)

Docker : 18.06.0-ce (edge)

Kubernetes : 1.10.3

I use Kubernetes for the first time.

I tried Google but could not find the manual for Kubernetes, which operates on the Mac.

Running kubectl version outputs The connection to the server localhost:8080 was refused - did you specify the right host or port?

Upvotes: 4

Views: 8447

Answers (5)

Florent Roques
Florent Roques

Reputation: 2662

For my part, Kubernetes was not enabled within Docker Desktop.
Here's how to enable Kubernetes on Mac:

  1. Click on settings on top right
  2. Click on "Kubernetes"
  3. Check "Enable Kubernetes"

enter image description here

Upvotes: 0

Ganesh Sundarapu
Ganesh Sundarapu

Reputation: 11

You might notice this error The connection to the server localhost:8080 was refused - did you specify the right host or port? because of your local minikube server might be down.

You have to start the existing minikube instance using - minikube start (I'm assuming your local minikube configured with docker driver earlier like: minikube start --driver=docker)

If not working above step then you have to delete the existing minikube then start it again:

minikube delete
minikube start --driver=docker

Upvotes: 1

Ryan McCormick
Ryan McCormick

Reputation: 112

I came across this issue when changing from minikube to the Docker Desktop supplied Kubernetes. For me, the issue was caused by a stale .kube configuration. Posting my workaround here as this was the first result I found on google when looking to troubleshoot the issue.

1. Uninstall Minikube

I had originally installed with homebrew: brew uninstall minikube. If installed using other methods, go back to your install source for uninstall info.

After minikube was uninstalled, I restarted my machine which may or may not have been necessary but it is what I did.

2. Disable Kubernetes in docker Desktop

  1. Open Docker Desktop preferences, click Kubernetes menu
  2. De-select 'Enable Kubernetes' checkbox. Click Apply & Restart

3. Remove old kube and minikube config

  1. Open terminal to your home directory.
  2. Check for settings directories: ls -al and look for .kube and .minikube.
  3. Remove .kube settings: rm -rf ./.kube.
  4. Remove .minikube settings: rm -rf ./.minikube.
  5. Confirm: ls -al and make sure the .kube and .minikube directories have been deleted.
  6. If everything looks good, close terminal.

4. Re-enable Kubernetes in Docker Desktop

  1. Open Docker Desktop preferences, click Kubernetes menu
  2. Select 'Enable Kubernetes' checkbox. Click Apply & Restart
  3. Open new terminal window and run kubectl version. You should see info for Client Version and Server Version if everything worked.

Upvotes: 5

dodSps
dodSps

Reputation: 43

I had faced the same issue and my user id did not had the admin privileges, once the chown is done, Kubernetes started working.Hope this helps

Upvotes: 0

sethmccombs
sethmccombs

Reputation: 91

When you run kubectl, the .kube/config file is read in your home directory, thus telling which cluster you want to connect to using --context=<cluster-name>

What your error output is telling you is that it is unable to find a listening kubernetes API endpoint upon which to run those commands. It is looking for a cluster at localhost:8080

This endpoint will vary depending on how and where you installed Kubernetes. How are you running Kubernetes?

Are you using the bundled Docker/Kubernetes for Mac as mentioned here? - Docker for Mac Kubernetes or are you using a tool like MiniKube? - MiniKube

Upvotes: 2

Related Questions