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


#1

Hello team,

I have installed kubernetes in centos.
After installation when i was checking the version with below command.

kubectl version -o json

I am getting error below along with version information.

{
  "clientVersion": {
    "major": "1",
    "minor": "11",
    "gitVersion": "v1.11.2",
    "gitCommit": "bb9ffb1654d4a729bb4cec18ff088eacc153c239",
    "gitTreeState": "clean",
    "buildDate": "2018-08-07T23:17:28Z",
    "goVersion": "go1.10.3",
    "compiler": "gc",
    "platform": "linux/amd64"
  }
}

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

Can you please check and advise.

Thanks,
Hemanth.


#2

Hi.
Check that the api server is actually running and hasn’t crashed:

docker ps | grep kube-apiserver

But the most likely problem and the one that usually gets me is that you don’t have a .kube directory with the right config in it. Try this:

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

#3

I have checked with below command

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

it is throwing below error.

cp: cannot stat ‘/etc/kubernetes/admin.conf’: No such file or directory

and i have check below, i could see it still running.

kubectl cluster-info
Kubernetes master is running at http://localhost:8080

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
The connection to the server localhost:8080 was refused - did you specify the right host or port?

but when i use curl localhost:8080 it is throwing below error.

curl localhost:8080
curl: (7) Failed connect to localhost:8080; Connection refused


#4

I’m encountering the same issue.

user@sqa02:/etc/kubernetes$ mkdir -p $HOME/.kube
user@sqa02:/etc/kubernetes$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
cp: cannot stat '/etc/kubernetes/admin.conf': No such file or directory
root@sqa03:~# kubectl cluster-info
Kubernetes master is running at http://localhost:8080

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
The connection to the server localhost:8080 was refused - did you specify the right host or port?
root@sqa03:~# curl localhost:8080
curl: (7) Failed to connect to localhost port 8080: Connection refused

To reproduce, follow the instructions provided on this techrepublic article.


#5

Hi there ,
any update on this ? I have the same problem now for this when i install minikube on Ubuntu 18.04 .

BR


#6

That error should only come up if you have no contexts configured in your client. If you run kubectl config view and you get something like this:

$ kubectl config view
apiVersion: v1
clusters: []
contexts: []
current-context: ""
kind: Config
preferences: {}
users: []

Then no contexts are configured.


#7

I have the same error, I tried running
kubectl config view
and I got the following:
apiVersion: v1
clusters:

  • cluster:
    insecure-skip-tls-verify: true
    server: https://localhost:6443
    name: docker-for-desktop-cluster
    contexts:
  • context:
    cluster: docker-for-desktop-cluster
    user: docker-for-desktop
    name: docker-for-desktop
    current-context: docker-for-desktop
    kind: Config
    preferences: {}
    users:
  • name: docker-for-desktop
    user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED

#8

I tried running the command you suggested. Do you have any further suggestions?


#9

This seems like another way to setup the cluster that said on the post (https://www.techrepublic.com/article/how-to-quickly-install-kubernetes-on-ubuntu/). Or is it using the same steps?

Getting kubectl to run really depends on how you installed it. Basically, if you install and have a proper config file, it should always work. So, either an old file from a previous installation is there or something silly like that (although usually difficult to spot).

Also, make sure the commands don’t fail (some on the post pasted that the step to copy the kubectl config failed). That is the way to authorize to the cluster, so it won’t never work if that step doesn’t work :slight_smile:

If I were you, I’d try removing everything from a previous run and starting from scratch and making sure nothing fails. If it does fail, try to fix that instead of continuing with the next steps. And if you can’t fix it, please report back with the steps you did, why it failed (the error) and what you tried and didn’t work.

This way it will be easier to solve :slight_smile: