How Do You Troubleshoot the Kubernetes Problem “connection to the server localhost:8080 was refused”?

One of the following applies (with #1 being related to Kubernetes anywhere and #2 only being relevant to running Kubernetes in GCP).

Problem scenario #1 (any Kubernetes)
You run a command like this: kubectl get svc

You get an error like this: The connection to the server localhost:8080 was refused - did you specify the right host or port?

What should you do?


Problem scenario #2 (in GCP only)
You created a Google Kubernetes cluster. From a server with kubectl, you run a kubectl command. Here is an example:

kubectl cluster-info dump

You receive this error: "The connection to the server localhost:8080 was refused - did you specify the right host or port?" What should you do?

Possible Solution #1
What is your $KUBECONFIG variable set to? Run this: echo $KUBECONFIG

This may remedy the problem, but replace "verycool" with the name of your cluster:

export KUBECONFIG=$KUBECONFIG:~/.kube/config-verycool

(You may want to do this: cd ~/.kube and run ls -lh.)

Possible Solution #2 (for GCP only)
1. Log into the web UI for GCP.
2. Search for "kubernetes engine".
3. Find the clusters that exist.
4. Mentally identify the name (e.g., standard-cluster-1) of the cluster and the region (e.g., us-central1-a).
5. In the upper righthand corner click on the icon ">_" (to activate the shell).
6. Stop the VM.
7. Click on the hyperlinked name of the VM.
8. Click "Edit"
9. Check the option to "Allow full access to all Cloud APIs" (unless the VM was created with the configuration such that it can run gcloud commands governing the Kubernetes engine).
10. Click Save.
11. Turn the VM on.
12. From the VM run this command (but substitute standard-cluster1 for the name of your cluster): gcloud container clusters get-credentials standard-cluster-1 --region us-central1-a

Possible Solution #3 (for EKS)
If you are running EKS (in AWS), see this posting.

Leave a comment

Your email address will not be published. Required fields are marked *